Argument Sources

Arguments to JS7 - JavaScript Jobs originate from a number of sources:

  • Workflow Variables
    • They are declared with the workflow and can hold default values. If no default value is specified then an order has to carry the variable and to assign a value. Otherwise an order optionally can assign a value to the variable.
    • Declared Variables include all variables declared with the workflow, optionally holding default values.
    • Order Variables include the variables specified with the order. This is a subset of the Declared Variables as carried by the order:
      • Orders are forced to specify variables for which no default value is declared.
      • Orders can specify any Declared Variables optionally over-ruling the variable's default value.
  • Job Arguments
    • The arguments are specified as key/value pairs with the given job. In case of multiple occurrence of the same job in a workflow the same arguments are used.
  • Node Arguments
    • The arguments are specified as key/value pairs with the job's node that is specific for the occurrence of a job in a workflow. Node Arguments allow to specify different argument sets if the same job is used a number of times in the workflow.
  • Job Resource Variables
    • The variables are specified as key/value pairs from JS7 - Job Resources
    • Job Resources can be assigned individually per job or to all jobs in a workflow.

Access to arguments by a job includes to read arguments from a specific source or to read all arguments.

Users who wish to keep things simple are invited to use access methods as explained with the next chapter Accessing Arguments. Subsequent chapters are aimed at users with a high load of possibly hundreds of arguments who require detailed information about the source of arguments.

Accessing Arguments

Download sample workflow implementing access to all arguments (upload .json): pdJavaScriptAllArguments.workflow.json

Reading specific Arguments

The straightforward way to read the value for a specific argument works like this:

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 specifying the argument name.
  • Argument values are returned in one of the supported data types including string, number and Boolean.
  • Consider that argument names are case-sensitive.

Reading the list of all Arguments

To iterate the list of available arguments the following proceeding applies:

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 example will return arguments from all sources.
  • Argument values are returned in one of the supported data types including string, number and Boolean.

Accessing Arguments from Order Variables

Order Variables are carried by an order and are a subset of the Declared Variables specified by the workflow.

  • Order Variables have to be specified for any Declared Variables that are not assigned a default value.
  • Order Variables can specify Declared Variables holding default values. The Order Variable overrules the default value.

Download sample workflow implementing access to Order Variables (upload .json): pdJavaScriptOrderVariables.workflow.json

Reading specific Order Variables

Order Variables can be accessed from their name like this:

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

	processOrder(js7Step) {
      	// access argument by name
        js7Step.getLogger().info('[getOrderArgumentsAsNameValueMap] by name:');
      	var colorBlue = js7Step.getOrderArgumentsAsNameValueMap()['color_blue'];
		js7Step.getLogger().info('argument color_blue=' + colorBlue);
    }
}

Reading the list of Order Variables

To iterate the list of Order Variables the following proceeding applies:

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

	processOrder(js7Step) {
        // get list of order variables
		var args = js7Step.getOrderArgumentsAsNameValueMap();
		js7Step.getLogger().info('[getOrderArgumentsAsNameValueMap]:');
		js7Step.getLogger().info('all arguments: ' + args);

        for (var arg in args) {
			js7Step.getLogger().info('argument: ' + arg + '=' + args[arg]);
		}
    }
}

Accessing Declared Arguments

Declaration of arguments includes the following levels:

  • Arguments that are declared by the workflow.
  • Arguments that are declared by the job implementation.

Declaration of arguments with a workflow looks like this:

  • At workflow level any number of variables can be specified.
  • Specification includes the data type, most frequently using string, number, Boolean.
  • A default value can be provided that allows an order to optionally specify the variable with some value.

Download sample workflow implementing access to Declared Arguments (upload .json): pdJavaScriptDeclaredArguments.workflow.json

Reading specific Declared Arguments

A job has to specify Declared Arguments by use of the js7.JobArgument class.

  • The argument specification can be redundant for arguments that are declared by the workflow.
  • The argument specification can introduce additional arguments that are not declared by the workflow. This suggests to specify a default value as otherwise an error is raised for a missing argument value.

Example for implementation of JS7Job with JavaScript
class JobArguments {
	colorBlue = new js7.JobArgument('color_blue', true);
}

class JS7Job extends js7.Job {
	declaredArguments = new JobArguments();

	processOrder(js7Step) {
        // option 1: access declared argument
      	// option 1.a: access declared argument by name
        js7Step.getLogger().info('[GetDeclaredArgument] by name:');
      	var declaredArg1a = js7Step.getDeclaredArgument('color_blue');
		js7Step.getLogger().info('declaredArgument: ' + declaredArg1a.getName() + '=' + declaredArg1a.getValue());

      	// option 1.b: access declared argument by object name
        js7Step.getLogger().info('[GetDeclaredArgument] by object name:');
      	var declaredArg1b = js7Step.getDeclaredArgument(this.declaredArguments.colorBlue.name);
		js7Step.getLogger().info('declaredArgument: ' + declaredArg1b.getName() + '=' + declaredArg1b.getValue());

        // option 2: access declared argument value
        // option 2.a: access declared argument value by name
		js7Step.getLogger().info('[GetDeclaredArgumentValue] by name:');
		js7Step.getLogger().info(js7Step.getDeclaredArgumentValue('color_blue'));

        // option 2.b: access declared argument value by object name
		js7Step.getLogger().info('[GetDeclaredArgumentValue] by object name:');
        js7Step.getLogger().info(js7Step.getDeclaredArgumentValue(this.declaredArguments.colorBlue.name));
    }
}

Explanations:

  • The example suggests two ways how to access declared arguments:
    • Accessing the argument value: directly returns the argument value for the given argument name.
    • Accessing the argument object: offers to use the getName() and getValue() methods of the argument object.
  • Argument names can be specified by strings or by using the declaredArguments instance of the JobArgument class and the argument objects included.

Reading the list of Declared Arguments

Similarly to reading specific Declared Arguments the job has to specify the Declared Arguments by use of the js7.JobArgument class.

Example for implementation of JS7Job with JavaScript
class JobArguments {
    // arguments with string data type
	colorBlue = new js7.JobArgument('color_blue', true, 'blue');
	colorRed = new js7.JobArgument('color_red', true, 'red');
	colorOrange = new js7.JobArgument('color_orange', true, 'orange');
  
    // arguments with numeric data type
    numOfDays = new js7.JobArgument('num_of_days', true, 5);
    // arguments with Boolean data type
    isEndOfMonth = new js7.JobArgument('is_end_of_month', true, true);

    // arguments with masked output that prevents values from being logged
    password = new js7.JobArgument('password', true, 'secret', js7.DisplayMode.MASKED);
}

class JS7Job extends js7.Job {
	declaredArguments = new JobArguments();

	processOrder(js7Step) {
        // get list of all declared arguments
		var args = js7Step.getAllDeclaredArguments();
		js7Step.getLogger().info('[getAllDeclaredArguments]:');
		js7Step.getLogger().info('all declared arguments: ' + args);

        for (var arg in args) {
			js7Step.getLogger().info('argument ' + args[arg].getName() + '=' + args[arg].getValue());
		}
    }
} 


Explanation:

  • The example declares a number of arguments with default values in different data types.
  • The getAllDeclaredArguments() method returns the list of arguments that can be iterated.

Accessing Job Resource Arguments

JS7 - Job Resources hold key/value pairs that are passed as arguments to a workflow (indicating all jobs) or to a specific job.

  • Any number of Job Resources can be assigned a job. When accessing arguments then all assigned Job Resources are taken into account.
  • JS7 implements a precedence of Job Resources holding the same variable names: the variable included with the first Job Resource assigned beats variables with the same name in subsequent Job Resources.

Download sample workflow implementing access to Job Resource Arguments (upload .json): pdJavaScriptJobResourceArguments.workflow.json

Reading specific Job Resource Arguments

Job Resource Arguments can be accessed from their name like this:

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

	processOrder(js7Step) {
      	// access argument by name
        js7Step.getLogger().info('[getJobResourcesArgumentsAsNameDetailValueMap] by name:');
      	var colorBlue = js7Step.getJobResourcesArgumentsAsNameDetailValueMap()['color_blue'];
		js7Step.getLogger().info("argument color_blue=" + colorBlue.getValue());
    }
}

Reading the list of Job Resource Arguments

The list of Job Resource Arguments is available for iteration like this: 

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

	processOrder(js7Step) {
        // get list of Job Resource arguments
		var args = js7Step.getJobResourcesArgumentsAsNameDetailValueMap();
		js7Step.getLogger().info('[getJobResourcesArgumentsAsNameDetailValueMap]:');
		js7Step.getLogger().info('arguments: ' + args);

        for (var arg in args) {
			js7Step.getLogger().info('argument: ' + arg + '=' + args[arg].getValue());
		}
    }
}

Further Resources