Introduction

This article explains how to access arguments and how to set return variables from a job implemented with Java.

Implementation

Receiving Arguments

Arguments are provided by environment variables that are mapped to the job.

In the example the environment variable VAR1 is used.

Returning Variables

Values can be returned as order return variables by writing key=value pairs to a temporary file that is provided by the Agent. There is one temporary file for each order in each workflow. The path to the temporary file is available from the environment variable JS7_RETURN_VALUES. The return variable is available with the next instruction in the workflow.


Receiving Arguments and returning Variables
package js7;

import java.io.FileWriter;
import java.io.IOException;

public class SetAndGetVariables {

	protected void setVar(String name, String value) throws IOException {
		try {
			String tmpFileName = System.getenv("JS7_RETURN_VALUES");
			FileWriter fw = new FileWriter(tmpFileName, true);              
            w.write(name + "=" + value + System.lineSeparator());
            fw.close();
		} catch (IOException ioe) {
			System.err.println("IOException: " + ioe.getMessage());
		}

	}

    protected String getVar(String name){
       return System.getenv(name);
	}

	public static void main(String[] args) throws IOException {

		SetAndGetVariables setAndGetVariables = new SetAndGetVariables();
		System.out.println("var1=" +  setAndGetVariables.getVar("VAR1"));
		setAndGetVariables.setVar("var1", "newValue");
	}

}