Passing a Parameter to a Shared Script

AlbreK01 (3 posts)
June 29, 2010 07:55 AM
Accepted Answer

I am a relatively newbie to adTempus.  I am skilled in VBScript.

I am struggling to figure out how to pass a parameter to a shared script (written in VBScript) when it is called from a step within an adTempus job.

Can somebody help me out here, please  .......

Thank you!

J.D. Staff (46 posts)
June 29, 2010 11:02 AM
Accepted Answer

There are two ways you can pass parameters to your script.

1) Define the parameters in Job Variables for the job (on the Variables tab for the job or the step) and retrieve the variables from the script. For example if you set a Job Variable called "MyParameter" you would use this to get the value in the script:

x=adTempus.JobVariables("MyParameter")

This is a good way to do it if you want to be able to change parameters without editing script code.

2) If you want to set the parameters programmatically instead of using Job Variables then you cannot do this with a shared script because a shared script does not accept function arguments. The way you would do it is create a Script Library that has your method defined with the necessary arguments. Then in the job you would use a regular script (not a shared script) that references the library and calls the method and passes it the arguments that you want to use. For example in the library you would have

sub MyFunction(param) ...

and then in the script you would call the method:

 MyFunction "paramvalue"

Air_Cooled_Nut (18 posts)
August 4, 2010 08:50 AM
Accepted Answer
Here's how we do it.  Remember, this is an EXAMPLE and it's up to you to change the variable names, code, and file path to suit your situation.  Hope this helps...

Go to the Job Properties and select the Steps tab.  Click Edit.  In the Program Execution Task Properties:
Set Target to:
cscript

Set Command-Line Parameters to:
cscript //nologo "\\celio\share\CCReportingDev\scripts\get_qclip_v1.wsf" /type:d /sbs:true

Your variables or command-line parameters are the items (in this example) /type: and /sbs:  The consist of a forward slash, the parameter name you want to use, and a colon.  The variable you pass in immediately follows the colon.  Of course, you can have zero to many parameters along with the standard VBScript parameters.

In your code you check for what was passed in.  Using my example above, here's the code that does the checking.  We put the parameter code at the top of the program, right after the DIM clause(s):

 

If IsEmpty(wscript.arguments.named("type")) Then 
    wscript.echo "Enter a value for 'type', 'd' for daily or 'w' for weekly." 
    wscript.quit(2) 
End If 
 
If wscript.arguments.named("type") = "d" Then 
'   sWriteLog "[Begin Daily Get_QCLIP.wsf]" 
    wscript.echo "Daily QCLIP" 
Else 
'   sWriteLog "[Begin Weekly Get_QCLIP.wsf]" 
    wscript.echo "Weekly QCLIP" 
End If 
 
' Build the suffix to the FILE_PREFIX_DAILY. 
If IsEmpty(wscript.arguments.named("DateOfData")) Then 
    dtDate = Date - 1 
Else 
    dtDate = wscript.arguments.named("DateOfData"
    If Not fMatch(DATE_PATTERN, dtDate) Then 
'       sWriteLog "     The format of the date entered was incorrectly." 
'       sWriteLog "[End Get_QCLIP.wsf]" 
        wscript.echo "The format of the date entered was incorrectly.  Process stopped." 
        wscript.quit(2) 
    End If 
End If 
 

The key component is wscript.arguments.name("stringName")
where stringName does NOT include the forward slash nor does it include the colon.  The forward slash simply lets the script know a parameter name is being passed and the colon separates the parameter name from the value being passed in.

You'll notice that I commented out writing to a log file, instead I output directly to the console.  This allows me to see what's going on if I run the processes manually AND! it allows the output to be captured by ad Tempus if you set the Window Mode: to Capture Console.  This way if there's an error I can check the Job Instance Details in the Captured Files tab and view the console output, helping me more quickly trouble-shoot.

I'm not a VBScript person (I normally program VBA) so I learned this stuff on the job so please excuse me if my exact terminology is off.  Good Luck!

Replies are disabled for this topic.