Job that calls other job in updating the variable from 1 to 10

Eduardo Menezes (20 posts)
October 31, 2022 11:57 AM
Accepted Answer

I have one job that I need to update the variable to run it.

For example, I update the variable to 1 and run the job; when it finishes, I update it to 2 and rerun the job... till ten or sometimes more than that.

Can I create one job1 to set from 1 to 10 (or more), and this job will call job2 but update the variable before calling job2?

It should work as a loop calling another job and updating its variable.

Bill Staff (602 posts)
November 3, 2022 10:09 AM
Accepted Answer

You can do this using a Response with a Job Control Action, paired with a script.

Create a new job.

In this job, add a Job Variable named "NumberOfRepetitions" with Integer data type and set it to 10 or whatever the count should be.

Add a step to run a script. Create a new script. Change the language to C# and paste in this code for the body:

using System;
using System.Collections.Generic;
using ArcanaDevelopment.adTempus.ApplicationIntegration;
using ArcanaDevelopment.adTempus.Shared;


namespace UserScript
{
    public class UserScript : ArcanaDevelopment.adTempus.ApplicationIntegration.UserScriptBase
    {
        public override Object Run()
        {
            var repetitions=int.Parse(adTempus.JobVariables["NumberOfRepetitions"]);
            for(int i=1;i<=repetitions;i++)
            {
                var parms=new ResponseParameters();
                parms.JobVariables["VariableForJob2"]=i.ToString();
                adTempus.ExecuteOnDemandResponses("RunTheJob", parms);
            }
            return 0;
        }
    }
}

In this sample it's setting the variable "VariableForJob2" to the counter. Change that to whatever variable name you need to use.

Save the script. Add a Response to the step. For the Event, select "Invoked by a script" and then for "Triggered by scripts using the following tag" enter "RunTheJob". For the Action, configure it to run job2.

If you need to have several jobs set up this way, you can check the Shared box in the script editor and save the script with a name; that way you can use the same script from the other jobs.

When you run the job it gets the repetition count from the "NumberOfRepetitions" job variable, then repeatedly sets the required variable to the counter and invokes the Response to run the job using that variable value.

Note that the script does not wait for job2 to finish before it submits the next instance. If you don't want them running at the same time, you need to edit job2 and go to the Triggers page. Change the "Multiple Instances" option to "Wait for the specified interval..." or "Execute only if..." and set a suitably long wait time.

If it's OK for them to be running at the same time, make sure the option is set to "Execute (start a new instance)".

I have attached an export file with 2 jobs demonstrating the setup. You can import them into your adTempus instance and review or adapt them. The "Call another job with script" job uses this technique to call "Target job".

 

Attachments