Sidebar

Is there a way to persist an object from one node to another?

0 votes
165 views
asked Jan 26 by scott-m-6181 (210 points)

Let's say that I have a blue mapping node. In the first step, I want to parse the source message and create an xml object. In subsequent steps, I want to re-use that xml object to populate the output message. One way to do it is to store a text string in the message cache, but then you have to parse it over and over in each step

STEP 1

messageCache.setValue('soap',
   qie.base64Decode(
      source.getNode('/Envelope/Body/ProvideAndRegisterDocumentSetRequest/Document')));

STEP 2

var document = qie.parseXMLString(messageCache.getValue('soap'));
var allergies = document.getNode('/ClinicalDocument/component/structuredBody/allergies/text/content');
message.setJSONString('/all', allergies);

STEP 3

var document = qie.parseXMLString(messageCache.getValue('soap'));
var procedures = document.getNode('/ClinicalDocument/component/structuredBody/procedures/text/content');
message.setJSONString('/procedures', procedures);

 

What I'm looking for is a way to store the XML object created from qie.parseXMLString() in a variable and persist it from step to step (or from node to node)

1 Answer

+1 vote
 
Best answer

You can achieve this by using a script variable.

Script variables are created in the Script Variable tab on a source node.  You can specify if they have a "channel" or "message" scope, which dictates if they are accessible to multiple messages or not.

Script variables can store objects; in your example you would create a script variable called 'soap' and assign your parsed XML string to it, like this:

soap = qie.parseXMLString(qie.base64Decode(source.getNode('/Envelope/Body/ProvideAndRegisterDocumentSetRequest/Document')));

 

From that point on, you could access the nodes by simply using soap.getNode(), like this:

var allergies = soap.getNode('/ClinicalDocument/component/structuredBody/allergies/text/content');

 

 

answered Jan 26 by jon-t-7005 (7,590 points)
selected Jan 27 by scott-m-6181
commented Jan 26 by leandro-g-5367 (100 points)
Thanks for your answer. This leads me to another question:

What's the difference between script variables and messageCache / messageCache channel?
commented Jan 26 by jon-t-7005 (7,590 points)
The major difference is the ability to store the object itself, rather than a string representation of the object.  Message Cache variables, as you found, are a string that needs to be parsed into an XML object upon each usage.  Script Variables hold the XML object itself, meaning you can access it just like you would a message or source object.
commented Jan 26 by nathan-c-4426 (540 points)
The main difference is messageCache/channelCache can only store Strings, Script Variables can store objects.  Also messageCache is just for a specific message can can't be shared by multiple messages while channelCache and scriptVariables can be accessed by other threads and so you do have to be consious of that.  If your channel has 5 threads processing messages and they're all using the same variable you could run into issues.

Another option not mentioned above would be to use setSharedCache() and getSharedCache() which also let you store any type of object similar to variables.  however they are in-memory only and differ from channel variables in that sense.  They're efficient and have an expiration option and can be used across messages and channels and functions and scripts.  You do have to be conscientious of threads however.    Just because they're thread safe, doesn't mean they're thread unique.
...