To access the order and/or job parameters from a job one must have access to the JS internal API. Implementing an API-Job, or a pre-/post-Processing routine, in Java or a script language that can implement the Job_impl interface, the access is possible via the [ JS objects|http://www.sos-berlin.com/doc/en/scheduler.doc/api/api-java.xml].
getting the objects
JS has two different types of parameters: 1) Task Params, which are used in jobs and 2) order params, which are used in orders. Both types of params are stored in different objects of type "Variable_set". To get all parameters, which are defined for a job, it is needed to get both and merge them together in a new object, which is not known to JS but to the program. This new object has at the end all parameters, and, if order parameters are merged after merging the task parameters, the order parameters will overwrite task parameters with the same name.
From a technical point of view the "merger" enables the program to run with "standalone" or with "Jobchain" jobs, as well.
The code shown below is part of the superclass [ JobSchedulerJobAdapter|http://www.sos-berlin.com/doc/doxygen-docs/scheduler/html/classsos_1_1scheduler_1_1job_1_1_job_scheduler_job_adapter.html], which is used for most of the latest JITL jobs:
1 protected [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Variable_set-java.xml Variable_set] getJobOrOrderParameters() \{ 2 @SuppressWarnings("unused") 3 final String conMethodName = conClassName + "::getParameters"; 4 try \{ 5 [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Variable_set-java.xml Variable_set] objJobOrOrderParameters = [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Spooler-java.xml spooler].create_variable_set(); 6 objJobOrOrderParameters.merge(getTaskParams()); 7 if (isJobchain() && hasOrderParameters()) \{ 8 objJobOrOrderParameters.merge(getOrderParams()); 9 \} 10 [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Log-java.xml logger].debug(String.format(Messages.getMsg(JSJ_D_0070), objJobOrOrderParameters.count())); 11 return objJobOrOrderParameters; 12 \} 13 catch (Exception e) \{ 14 throw new JobSchedulerException(String.format(Messages.getMsg(JSJ_F_0050), e.getMessage()), e); 15 \} 16 \} 17 protected [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Variable_set-java.xml Variable_set] getTaskParams() \{ 18 return [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Task-java.xml spooler_task].params(); 19 \} 20 protected [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Variable_set-java.xml Variable_set] getOrderParams() \{ 21 return [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Task-java.xml spooler_task].order().params(); 22 \}
Let's have a look at the Java code:
- On line 5 a [ Variable_set|http://www.sos-berlin.com/doc/en/scheduler.doc/api/Variable_set-java.xml] is created from scratch. It is empty.
- on line 6 the content of the task parameters is merged into this Variable_set
- on line 7 and 8 the order parameter, if the job runs as a jobchain job, will merged as well into the Variable_set
get a variable value
To get a variable from the object "Variable_set" one have to use the method "var":
[http://www.sos-berlin.com/doc/en/scheduler.doc/api/Variable_set-java.xml Variable_set] objVariables = getJobOrOrderParameters(); String myVar = objVariables.var("myVarName"); String myVar2 = objVariables.var("nextVarname);
If the variables with the given name does not exist the value of the result variable will be null. The Values of the JobSchedulers variables are always of type "String".
Set variable values
public void setJSParam(final String pstrKey, final String pstrValue) \{ @SuppressWarnings("unused") final String conMethodName = conClassName + "::setJSParam"; if (isNotNull(spooler_task.params())) \{ [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Task-java.xml spooler_task].params().set_var(pstrKey, pstrValue); \} if (hasOrderParameters()) \{ [http://www.sos-berlin.com/doc/en/scheduler.doc/api/Task-java.xml spooler_task].order().params().set_var(pstrKey, pstrValue); \} if (isNotNull(objJobOrOrderParams)) \{ objJobOrOrderParams.set_var(pstrKey, pstrValue); \} \}
To set a variable or change the actual value of a variable one must code
setJSParam("myVariable", "the.value");
It is important to take into account, that the modification of a variable is only effective for JS if this modification is done in the JS object and not in the copy which is provided by the Method getJobOrOrderParameters.
<!--
related downloads
-->
see also
- [ internal API for Java|http://www.sos-berlin.com/doc/en/scheduler.doc/api/api-java.xml]
- [ Variable_set|http://www.sos-berlin.com/doc/en/scheduler.doc/api/Variable_set-java.xml]
- [ JobSchedulerJobAdapter|http://www.sos-berlin.com/doc/doxygen-docs/scheduler/html/classsos_1_1scheduler_1_1job_1_1_job_scheduler_job_adapter.html]
- [ internal API-Jobs|http://www.sos-berlin.com/doc/en/scheduler_tutorial.pdf]
[back to FAQ main page|JobScheduler_FAQ]