AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Json object cann’t be transfered between rules in variable
 
 

Linux, CS 6.83
With this code and with json mentioned in first line a: () rule is skipped by CS

# :json crm-data {"error" : "rghr", "token" : "sometok_enblyat", "accounts" : [{"token": "anytoken1", "name" : "Westwood"}, {"token": "anytoken2", "name" : "Forestpaper"}] }
u: (\:json _*1 _*)
$$counter = 0
# $orjs = ^original( _1 )
$crmdata = ^jsonparse( ^original( _1 ) )
$tmp = ^jsonpath(.accounts $crmdata)
$tmp = ^length($tmp)
${tcard\: navigation-card\: {"items"\: \[
loop( $tmp )
{
\{"title"\: \" ^jsonpath(.accounts.$$counter.token $crmdata )\" \} 
  $$counter += 1
  if ($$counter < $tmp) { , }
  }
\]}$}

a: ( )
  $crmdata.error


The next code works as expected (transfer json as usual string)

u: (\:json _*1 _*)
$$counter = 0
$orjs = ^original( _1 )
$$crmdata = ^jsonparse( ^original( _1 ) )
$tmp = ^jsonpath(.accounts $$crmdata)
$tmp = ^length($tmp)
${tcard\: navigation-card\: {"items"\: \[
loop( $tmp )
{
\{"title"\: \" ^jsonpath(.accounts.$$counter.token $$crmdata )\" \} 
  $$counter += 1
  if ($$counter < $tmp) { , }
  }
\]}$}

a: ( )
  $$crmdata = ^jsonparse( $orjs )
  $$crmdata.error

 

 
  [ # 1 ]

This is because, by default, ^jsonparse generates transient JSON facts and so they will be deleted at the end of the volley.
As the rejoinder, the a: rule, is invoked on the next volley then $crmdata is pointing to nothing.

Your version that works is because you are storing a string in a permanent variable.

For the first version to work then you need to create permanent json facts via ^jsonparse(permanent ^original(_1)).
But be aware that you will have to take care of the cleanup and do a ^delete($crmdata) (and $crmdata = null) at some point.

 

 
  login or register to react