My channel is receiving HL7 messages and I have 2 transformers in my channel. I am capturing all the data from the HL7 message in one transformer like:
- var vACCNo= msg['PID']['PID.17']['PID.17.1'].toString();
- var vSTATE=msg['PID']['PID.11']['PID.11.4'].toString();
- .... In the second transformer I am pushing all this data into a external DB as insert statement like insert into table x values (vACCNo, vSTATE....).
In the above design without doing anything data captured in first transformer is available in second and it works.
Now I am planning to get rid of these 2 transformers and move these into code templates, where I'm planning to create a separate function for each of these transformer.
But how I can pass variables captured in first function to second one?
Thanks
When you say 2 transformers, I assume you mean two steps in the same transformer? Different transformer steps compile into the same javascript function, so they share the same variable context/scope. To actually pass values to a different transformer (like from your source transformer to a destination transformer) normally you would use the channelMap for this.
In your (presumed) situation, you can add all of your variables to an object that you return from the first function. Pass the object to the second function.
Code Templates
Transformer steps
var obj = getValues(msg);var result = insertIntoDb(obj);