No announcement yet.

Mapping variables from preprocessor

  • Filter
  • Time
  • Show
Clear All
new posts

  • Mapping variables from preprocessor

    Is it possible to read/write to/from the channel or global maps in a preprocessor script? I did a forum search but couldn't find a definitive answer.


  • #2
    I am also having this problem

    This is my preprocessor:

    // Modify the message variable below to pre process data
    globalChannelMap.put('Patient_ID','0');$(Patient_ID));'is this running');
    return message;

    I am having issues with defining global values in the preprocessor.
    The only information the above code gives in the Log Information is the following error:

    [2013-12-19 17:53:19,355] ERROR (com.mirth.connect.server.util.JavaScriptUtil:264) : Error executing Preprocessor script from channel: 172bd389-d686-4ac6-b705-6b2e6a724088
    com.mirth.connect.server.MirthJavascriptTransforme rException: SOURCE CODE:

    ReferenceError: "Patient_ID" is not defined.

    I cut out some of the information; the big issue for me is the error name. I literally just get done defining the variable and it kills the whole preprocessor saying it's undefined.
    This also kills my code as I need to call the variable in the source transformer before defining it further down the line.

    Any suggestions?

    EDIT: got help on the IRC channel. have to watch my quotes in the future.
    So yes, globals can be changed and called in the preprocessor
    Last edited by ben.germann; 12-19-2013, 11:28 AM.


    • #3
      I am having the following line of code in preprocessor of my channel where I am writing to the global channel map variable.

      globalChannelMap.put('InitMirthServerLocation', 'LAV Mirth development server');

      And I am able of get the value in destination transformer javaScript globalChannelMap.get('InitMirthServerLocation');


      • #4
        To access the value stored in a global variable, use this form:

        $('<GlobalVarName>')  <-- Note the single quotes
        All variables in all contexts are referenced this way.
        Last edited by Jon Blanchard; 05-27-2014, 01:24 AM.