You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

To access the order and/or job parameter from a job one must have access to the JS internal API. Implementing an API-Job in Java or a script language, which can implement "spooler_process", the access is possible via the JS objects.

JS has two different types of paramters: 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 from 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 know 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, 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 = spooler.create_variable_set();
  6          objJobOrOrderParameters.merge(getTaskParams());
  7          if (isJobchain() && hasOrderParameters()) \{
  8              objJobOrOrderParameters.merge(getOrderParams());
  9          \}
 10         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 \}
    protected [[http://www.sos-berlin.com/doc/en/scheduler.doc/api/Variable_set-java.xml |Variable_set]] getTaskParams() \{
        return spooler_task.params();
    \}
    protected [[http://www.sos-berlin.com/doc/en/scheduler.doc/api/Variable_set-java.xml |Variable_set]] getOrderParams() \{
        return spooler_task.order().params();
    \}

Lets have a look at the Java code:

  1. On line 5 a Variable_set is created from scratch. It is empty.
  2. on line 6 the content of the task parameters are merge into this Variable_set
  3. on line 7 and 8 the order parameter, if the job runs as a jobchain job, will merged as well into the Varable_set

get a variable value

To get a variable from the object "Variable_set" one have to use the method "var":

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())) \{
            spooler_task.params().set_var(pstrKey, pstrValue);
        \}
        if (hasOrderParameters()) \{
            spooler_task.order().params().set_var(pstrKey, pstrValue);
        \}
        if (isNotNull(objJobOrOrderParams)) \{
            objJobOrOrderParams.set_var(pstrKey, pstrValue);
        \}
    \} 

related downloads

see also

  • No labels