0

I have written this code in mirth to capture code from each DG1 segment but it captures 'undefined' and inserts in DB

for each (seg in msg.children()){ 
    if(seg.name().toString()=="DG1"){
      var vSET_ID =msg['DG1']['DG1.1'].toString();
    if(vSET_ID==1){
      var vPriCode = msg['DG1']['DG1.3']['DG1.3.1'].toString(),50);
    if(vSET_ID==2){
      var vSecCode1 = msg['DG1']['DG1.3']['DG1.3.1'].toString(),50);

Thanks

Freiheit
  • 8,408
  • 6
  • 59
  • 101
  • 1
    Your code has lots of unmatched brackets - is this actually so or has something gotten lost in copying and pasting? – Tarmo R Oct 15 '18 at 13:28
  • 1
    Instead of var vSET_ID =msg['DG1']['DG1.1'].toString(); use var vSET_ID = seg['DG1.1'].toString(); – Shamil Oct 16 '18 at 14:54

1 Answers1

0

There are many syntax and logic errors in your code. If you intend to use these in a Database writer, you'll have to save them to a Map variable (channelMap or connectorMap would make sense here.) If you want to capture DG1.3.1 from the first and second occurrence of the DG1 segment, you may want to avoid Javascript steps in your transformer and try replacing your code with two Mapper steps where:

  1. First step
    • Variable := vPriCode
    • Mapping := msg['DG1'][0]['DG1.3']['DG1.3.1'].toString()
  2. Second step
    • Variable := vSecCode
    • Mapping := msg['DG1'][1]['DG1.3']['DG1.3.1'].toString()

These variables should now be available in the Destination Mappings drag-and-drop section of your database writer. This does make the assumption that the SetIDs appear in order.

(I was going to post screenshots, but my reputation is not high enough.)

agermano
  • 1,679
  • 6
  • 16