Configuring a Shared Script to run as a Step or Condition

Andrew (22 posts)
September 13, 2016 02:14 PM
Accepted Answer

Hi,

I've written some Shared Scripts that act as generic utilities. I have some instances where I'd like to use these scripts as a job condition in some jobs and as a job step in other jobs.

For a condition, I have the scripts returning true or false. For a step, I have them returning a numeric value. Is it possible to sniff out how the script is being used at runtime and set the return value based on that property?

For example:

if (adTempus.SomeCollection["someProperty"] == "condition")
{   
     return true/false;
}
else if (adTempus.SomeCollection["someProperty"] == "step")
{   
     return 0/1/2;
}


Bill Staff (599 posts)
September 13, 2016 02:29 PM
Accepted Answer

Good question. I'm surprised it hasn't come up before. Unfortunately there's no way for the script to know how it's being used.

I'll write up an enhancement request to provide this information. Also I think we can pretty easily change things so the Script Execution Task (running script as a step) will accept a true/false response instead of a numeric result.

Meanwhile (or if you're using adTempus 3), the best way to handle this would be to move your code from a Shared Script to a Script Library, implemented as functions that return a numeric result. Then have two shared scripts that are designated as the "Condition" version and the "Task" version. Each would call the code from the library. The "Task" version would return the function result back to adTempus; the "Condition" version would return true or false based on whether the return value was 0 or something else.

Andrew (22 posts)
September 13, 2016 03:21 PM
Accepted Answer

The Shared Library is a great workaround. I just coded this up and it works perfect.I like that I can adjust the functionality slightly for each implementation. I'm calling a SQL Server stored procedure and want to insert a Thread.Sleep() so I'm not constantly banging on the database when it as a condition.

Thanks, Bill.

Replies are disabled for this topic.