Introduction

JS7 offers a number of JS7 - Job Classes including JS7 - Shell JobsJS7 - Java Jobs and JavaScript Jobs.

JS7 offers the JS7 - Job API to JavaScript Jobs that serves the purpose of

  • accessing arguments available to the job from various sources such as JS7 - Order Variables, job and node arguments, JS7 - Job Resources,
  • allowing to specify the outcome of a job including return values that are passed to subsequent jobs from order variables.

JavaScript jobs are available starting from the following releases:

FEATURE AVAILABILITY STARTING FROM RELEASE 2.5.4

FEATURE AVAILABILITY STARTING FROM RELEASE 2.6.1

Implementation

Implementing a basic Job

A JavaScript Job is implemented by a class with the name JS7Job like this:

Example for implementation of JS7Job with JavaScript
class JS7Job extends js7.Job {

	processOrder(js7Step) {
		js7Step.getLogger().info( 'hello world' ); 		

		// do some stuff
    }
}


Explanation:

  • The implementation class with the name JS7Job is required.
  • The processOrder() method is required to be implemented by the job.
    • The method is parameterized by the js7Step object provided by the Job API.
    • The js7Step object is used with its getLogger() method to write output to the job's log.

Accessing Arguments

A JavaScript Job can access arguments from a number of sources, see JS7 - Job API

Example: Reading specific Arguments

Example for implementation of JS7Job with JavaScript
class JS7Job extends js7.Job {
 
    processOrder(js7Step) {
        // access argument by name
        js7Step.getLogger().info('[getAllArgumentsAsNameValueMap] by name:');
        var colorBlue = js7Step.getAllArgumentsAsNameValueMap()['color_blue'];
        js7Step.getLogger().info('argument color_blue=' + colorBlue);
    }
}

Explanation:

  • The getAllArgumentsAsNameValueMap() method provides a map of all arguments. The map allows to read a single argument from the argument name.
  • For further methods to access arguments see JS7 - Job API

Example: Reading the list of Arguments

Example for implementation of JS7Job with JavaScript
class JS7Job extends js7.Job {
 
    processOrder(js7Step) {
        // get list of all arguments
        var args = js7Step.getAllArguments();
        js7Step.getLogger().info('[getAllArguments]:');
        js7Step.getLogger().info('all arguments: ' + args);
 
        for (var arg in args) {
            js7Step.getLogger().info('argument: ' + arg + '=' + args[arg].getValue());
        }
    }
}


Explanation:

  • The getAllArguments() method provides an array of argument objects for iteration.
  • For further methods to access arguments see JS7 - Job API

Further Resources

Features

Articles

How To ... JavaScript



  • No labels