Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

Sometimes it's convenient to develop PJS applications in a PJS instance installed on your PC, before deploying to a network server or IBMi system. This tip documents how to use commands PJSMYIP and PJSCALL to call a "regular" (i.e. NOT low-code) PJS module on your PC from an IBMi system.

In the following example, we'll create a "regular" PJS module in your PJS instance on your PC, call it with 2 input parameters, and see the output in the console log.

  • Navigate to the workspace "pjstips".
  • Click New/Javascript File.
  • Enter the code below. Click Save As, and save as pjstips_07_1.js. Note that this is very simple code, as an example. You can do anything you want here (e.g. use various PJS API's such as pjs.define(), call pjs.query() to get data, use pjs.call() to call an IBMi program, etc).


function app(firstName, lastName) {

  pjs.define("firstName",   { type: 'char', length: 30,  refParm: firstName });
  pjs.define("lastName" ,   { type: 'char', length: 30,  refParm: lastName  });
  
  let fullName = `${firstName.trim()} ${lastName.trim()}`;
  console.log(`fullName = ${fullName}`);
 
}

exports.run = app;

exports.parms = [
  { type: 'char', length:  30 },      // firstName            
  { type: 'char', length:  30 }       // lastName        
];

  
  • Note that this is in the format of a "regular" (i.e. NOT low-code) PJS module. It's also NOT a module meant to be called as an Express Route (web service) as in the example here. It does NOT have the "req" and "res" parameters as in a module meant to be called as web service. Instead, it has zero or more "usual" parameters that you can pass to the module, either from another PJS module or from command PJSCALL.
  • You can call this module from an IBMi green-screen, using the command PJSCALL. The green-screen session could be a Genie session, but it does NOT have to be. A Genie session is required only if the PJS module uses an RDF (Rich Display File).
  • Note that we'll use command PJSCALL (*CMD object) to call this PJS module. It's NOT the program PJSCALL (*PGM object) that's used to call low-code modules. This could be a source of confusion. We'll clarify it further in a future tip.
  • On your IBMi system, in a green-screen session, run the following command to direct the call to the PJS instance installed on your PC. Use the port number for that PJS instance; default is 8081 as used in this example.
PJSMYIP PORT(8081)
  • After that command is run, the environment variables PROFOUNDJS_COMM_HOST and PROFOUNDJS_COMM_PORT (of your interactive job only, not system-wide) should be updated so that any PJSCALL will call the PJS module on your PC. Run command WRKENVVAR to verify. Should look something like this.
PROFOUNDJS_COMM_HOST        '172.16.1.120'
PROFOUNDJS_COMM_PORT        '8081'  
  • Run following command to call the PJS module on your PC.
PJSCALL MODULE('pjstips/pjstips_07_1.js')        
        PARM('John' 'Smith')                     
  • Since the "PATH" parameter does NOT start with a "/", that path is relative to the directory <PJS_instance_dir>/modules. The .js file you created previously in workspace "pjstips" should have been created in directory <PJS_instance_dir>/modules/pjstips.
  • The console log should show the output like this:
fullName = John Smith


  • No labels