Automic Workload Automation

Expand all | Collapse all

Extracting values from Javascript External Interpreter

Jump to Best Answer

Michael Lowry03-26-2019 06:00 AM

  • 1.  Extracting values from Javascript External Interpreter

    Posted 03-19-2019 05:10 PM

    Hi guys,

     

    I followed this post here (:REGISTER_VARIABLE — practical examples with Bash, Perl, Python, Ruby, and PowerShell) and the documentation to add node.js as interpreter

     

    and I'm able to run JavaScript code,

    but I'm not able to get them using :REGISTER_VARIABLE

    Everything is blank.

    I believe I'm missing a step from Michael's practical examples.



  • 2.  Re: Extracting values from Javascript External Interpreter

    Posted 03-20-2019 11:48 AM

    I’ve played around with node.js, and had limited success. I was able to get node.js jobs running via an external interpreter for jobs of type Interpreter. But :REGISTER_VARIABLE wasn't working. I discovered that on my system, REGISTER_VARIABLE.WINDOWS (in client 0) is configured so that :REGISTER_VARIABLE will work only for jobs of type BAT.

    :set &uc_register_varname  = sys_last_registered_varname()
    :set &uc_register_valuename = sys_last_registered_valuename()
    :set &uc_register_otype# = sys_act_me_type()
    :if &uc_register_otype# = 'JOBS'
    :  set &uc_windows_typ = get_att(win_typ)
    :  if &UC_WINDOWS_TYP = "BAT"
    &UC_JOBMD JNR=&UC_REALNR MNR=&UC_MANDANT PNR=&UC_IP_PORT IPA=&UC_IP_ADR TYP=V VTYPE=T NAME=&uc_register_varname VALUE="&uc_register_valuename"
    :  endif
    :endif

     

    If you turn on extended reports and look at the Script tab of the report, you can see where :REGISTER_VARIABLE is being expanded. (In this context, :REGISTER_VARIABLE is shortened to just :RGSTV).

     var var1 = "Hello, world.";
    console.log(var1);
    :RGSTV             VARIABLE_1#,var1
    :set &uc_register_varname  = sys_last_registered_varname()
    :set &uc_register_valuename = sys_last_registered_valuename()
    :set &uc_register_otype# = sys_act_me_type()
    :if &uc_register_otype# = 'JOBS'
    :  set &uc_windows_typ = get_att(win_typ)
    :  if &UC_WINDOWS_TYP = "BAT"
    &UC_JOBMD JNR=&UC_REALNR MNR=&UC_MANDANT PNR=&UC_IP_PORT IPA=&UC_IP_ADR TYP=V VTYPE=T NAME=&uc_register_varname VALUE="&uc_register_valuename"
    :  endif
    :endif
    :END_EXT_INT NODEJS
    /h

    Making the command run for other cases is not enough though. In addition, the job messenger command will have to be updated for the special case where &$EXT_INTERPRETER# = "NODE" because the syntax will be different from inside node.js. If I get time, I might experiment more with it later.



  • 3.  Re: Extracting values from Javascript External Interpreter

    Posted 03-21-2019 01:54 PM

    Ok, I figured it out. I gave up getting it working on Windows, and switched to UNIX.

     

    REGISTER_VARIABLE_UNIX

    :set &uc_register_varname   = sys_last_registered_varname()
    :set &uc_register_valuename = sys_last_registered_valuename()
    :set &uc_register_otype#    = sys_act_me_type()
    :if &uc_register_otype# = 'JOBS'
    :SWITCH &$EXT_INTERPRETER#
    :CASE 'NODEJS'
    var cmd = "&UC_JOBMD JNR=&UC_REALNR MNR=&UC_MANDANT PNR=&UC_IP_PORT IPA=&UC_IP_ADDR TYP=V VTYPE=T NAME=&uc_register_varname VALUE=\"" + &uc_register_valuename + "\"";
    console.log("Registering variable '&uc_register_varname' with value '&uc_register_valuename'.");
    console.log("Job messenger command: " + cmd);
    const { exec } = require('child_process');
    exec(cmd, (err, stdout, stderr) => {
      if (err) {
        // node couldn't execute the command
        return;
      }
      // the *entire* stdout and stderr (buffered)
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
    });
    :OTHER
    &UC_JOBMD JNR=&UC_REALNR MNR=&UC_MANDANT PNR=&UC_IP_PORT IPA=&UC_IP_ADDR TYP=V VTYPE=T NAME=&uc_register_varname VALUE="&uc_register_valuename"
    :ENDSWITCH
    :endif

     

    You can remove the extra console messages once you're confident that it works. Note too that I chose the name NODEJS instead of NODE for the Node.js interpreter.



  • 4.  Re: Extracting values from Javascript External Interpreter

    Posted 03-22-2019 05:37 AM

    It seems to me that it would make more sense if the script variable &uc_register_valuename were named &uc_register_varvalue.

    Then the two variables would be named:

    • &uc_register_varname
    • &uc_register_varvalue


  • 5.  Re: Extracting values from Javascript External Interpreter

    Posted 03-26-2019 06:00 AM

    deama10: Did my solution work?



  • 6.  Re: Extracting values from Javascript External Interpreter

    Posted 03-26-2019 04:38 PM

    Even with your register_variable code, I keep getting

     

    as an empty variable

    Using

    The report



  • 7.  Re: Extracting values from Javascript External Interpreter

    Posted 03-27-2019 03:08 AM

    Yeah, that's also what I saw on Windows. The same bit of code works fine on UNIX.



  • 8.  Re: Extracting values from Javascript External Interpreter

    Posted 03-29-2019 09:04 AM

    I have figured out why it wasn't working on Windows. The default include (JOBI) objects do not set all of the variables need by the job messenger daemon if the Windows job sub-type is Interpreter. As I looked into this, I also discovered a larger problem:

    The variable that contains the IP address of the agent is not named consistently in the initial data objects.

    $ grep '&UC_IP_ADR' uc_ini.txt | wc -l

    31

    $ grep '&UC_IP_ADDR' uc_ini.txt | wc -l

    45

    • In some places, it’s called &UC_IP_ADDR (like the virtual agent VARA object UC_EX_IP_ADDR).
    • In other places, it’s called &UC_IP_ADR (with one D missing — in bold below).

     

    Header JOBIScript variable name for UC_EX_IP_ADDR
    HEADER.BS2000&UC_IP_ADR
    HEADER.GCOS8&UC_IP_ADDR
    HEADER.MPE&UC_IP_ADDR
    HEADER.MVS&UC_IP_ADR
    HEADER.OS400&UC_IP_ADR
    HEADER.UNIX&UC_IP_ADDR
    HEADER.VMS&UC_IP_ADDR
    HEADER.WINDOWS&UC_IP_ADR


  • 9.  Re: Extracting values from Javascript External Interpreter

    Posted 05-07-2019 04:56 AM

    Michael Lowry wrote:

    The variable that contains the IP address of the agent is not named consistently in the initial data objects.

    • In some places, it’s called &UC_IP_ADDR (like the virtual agent VARA object UC_EX_IP_ADDR).
    • In other places, it’s called &UC_IP_ADR (with one D missing — in bold below.).

     

    Header JOBIScript variable name for UC_EX_IP_ADDR
    HEADER.BS2000&UC_IP_ADR
    HEADER.GCOS8&UC_IP_ADDR
    HEADER.MPE&UC_IP_ADDR
    HEADER.MVS&UC_IP_ADR
    HEADER.OS400&UC_IP_ADR
    HEADER.UNIX&UC_IP_ADDR
    HEADER.VMS&UC_IP_ADDR
    HEADER.WINDOWS&UC_IP_ADR

     

    CA Development responded:

    These definitions do not match overall, but will stay so for compatibility reasons.

    If a uniform naming is needed for custom include objects, the UC_EX_IP_ADDR variable should be used.

     

    And indeed, that is what I ended up doing. In my JOBIs, I set my own script variable based on the virtual VARA UC_EX_IP_ADDR, rather than relying on the script variable set in the header include.



  • 10.  Re: Extracting values from Javascript External Interpreter



  • 11.  Re: Extracting values from Javascript External Interpreter

    Posted 03-26-2019 04:32 PM

    Sorry Michael, I've been a little busy.

     

    I did manage to run Node on windows, just have to use the correct variable

     

     

    But let me try your  block and I'll give you a feedback



  • 12.  Re: Extracting values from Javascript External Interpreter
    Best Answer

    Posted 04-02-2019 09:37 AM

    deama10: I updated my JOBIs to add support for Node.js. Perhaps you’d like to add support for Groovy?

    :REGISTER_VARIABLE — practical examples with Bash, Perl, Python, Ruby, PowerShell, & Node.js 



  • 13.  Re: Extracting values from Javascript External Interpreter

    Posted 04-03-2019 11:06 AM

    Did you manage to get it working for windows?



  • 14.  Re: Extracting values from Javascript External Interpreter

    Posted 04-03-2019 11:28 AM

    Yes, it works fine. See my examples attached to the document.



  • 15.  Re: Extracting values from Javascript External Interpreter

    Posted 04-03-2019 12:54 PM

    I'm getting a wierd error when I'm trying to run in another context (when I ran your job it worked great)

    it looks like it has an extra c:\, for some reason



  • 16.  Re: Extracting values from Javascript External Interpreter

    Posted 04-03-2019 01:53 PM

    Is the Windows job sub-type BAT? If so, I think the extra C:\ comes from the working directory field. I didn’t take the time to figure out exactly how it works, because I quickly discovered that fixing it would require changing the default Windows header includes.

     

    I quickly found out that it worked more predictably if I set the sub-type to Interpreter, and I stuck with that.



  • 17.  Re: Extracting values from Javascript External Interpreter

    Posted 04-03-2019 02:36 PM

    Thanks, I'll use the custom interpreter option!



  • 18.  Re: Extracting values from Javascript External Interpreter

    Posted 04-03-2019 03:13 PM

    Michael_Lowry,

     

    When I try to register more than one variable in the script it keeps saying that the rvexec s already defined, how would I solve this in the interpreter definition?

     



  • 19.  Re: Extracting values from Javascript External Interpreter

    Posted 04-03-2019 04:10 PM

    The code in REGISTER_VARIABLE.NODEJS has to be modified to declare rvexec only if it hasn't already been declared.



  • 20.  Re: Extracting values from Javascript External Interpreter

    Posted 04-04-2019 03:47 AM

    Change the 'const rvexec...' line to this:

    if (typeof rvexec == 'undefined') { var rvexec = require('child_process').exec };

    I’ll make sure multiple variables can be registered in all languages and then update the VARAs attached to the document.



  • 21.  Re: Extracting values from Javascript External Interpreter

    Posted 04-04-2019 05:42 AM

    OK, done. I also made sure registration of variable values containing special characters like spaces works in all interpreters.



  • 22.  Re: Extracting values from Javascript External Interpreter

    Posted 04-12-2019 04:51 AM

    I have gotten Groovy working, mostly. :REGISTER_VARIABLE now works, but for some reason :REGISTER_OUTPUT file doesn’t work completely. It registers the file with the AE, but the file cannot be downloaded. The problem might be related to the bug described in KB000121406. As soon as I figure it out, I’ll post an update. deama10, if you get it working, let me know.