Page History
...
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 required detailed information about the source of arguments.
Accessing Arguments
Download sample workflow implementing access to all arguments (upload .json): pdJavaScriptAllArguments.workflow.json
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
class JS7Job extends js7.Job { processOrder(js7Step) { var workflowPath = js7Step.getAllArgumentsAsNameValueMap['js7Workflow.path']); js7Step.getLogger().info('argument: ' + workflowPath); } } |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
class JS7Job extends js7.Job { processOrder(js7Step) { var args = js7Step.getAllArguments(); for (var arg in args) { js7Step.getLogger().info('argument: ' + arg + '=' + args[arg]); } } } |
...
- 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 over-rules the default value.
Reading specific Order Variables
Order Variables can be accessed from their name like this:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
class JS7Job extends js7.Job { processOrder(js7Step) { var workflowPath = js7Step.getAllArgumentsAsNameValueMap['js7Workflow.path']); js7Step.getLogger().info('argument: ' + workflowPath); } } |
Reading the list of Order Variables
Accessing Declared Arguments
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
class JobArguments { workflowPath = new js7.JobArgument('js7Workflow.path', 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('js7Workflow.path'); 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.workflowPath.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('js7Workflow.path')); // option 2.b: access declared argument value by object name js7Step.getLogger().info('[GetDeclaredArgumentValue] by object name:'); js7Step.getLogger().info(js7Step.getDeclaredArgumentValue(this.declaredArguments.workflowPath.name)); } } |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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('declared argument: ' + arg + '=' + args[arg]); } } } |
...
- 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:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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
...