Entering or verifying parameters when a job starts

Paul Watson (101 posts)
January 16, 2017 10:31 AM
Accepted Answer

We have a job that requires two (2) parameters; a start date and end date. For example, we might need to extract data from a database table created between 2014-01-01 and 2015-01-01. We have a parameterized database process that will do the work.

Each time this job is run will typically require a different date range or would, at a minimum, require human verification that this is the intended date range to be processed.

I have, and could, gather the date range parameters from a file and pass them to the database program. The user could edit the command line parameters in the adTempus job step.

I am wondering if there is any way to have a popup appear that would allow the user to validate or possibly change the two (2) parameter values? This should only occur on a manual run of the job. If the job is triggered or chained, then there would be no user interaction.

I am guessing that a PowerShell (or other) could be run as a Step 1 of the job. But how can it detect a manually run job instance and how can it change the parameters used for Step 2? Better yet, is there an easier way?

Bill Staff (599 posts)
January 16, 2017 12:11 PM
Accepted Answer

You are not going to be able to run anything as part of your job to display a popup to prompt the user to review/set values: The only way a program/script run by adTempus can interact with the user is if the job is running under the user's account, and the user is logged in at the time of execution.

One way I can think of to get close to what you want: define two Job Variables for your for the StartDate and EndDate. In the step that runs your process, you would use variable tokens (e.g., "%StartDate%") to insert the values in the command line. In the variable definition, don't specify an initial value.

When a user runs a job manually, the execution options window has a tab where they can set/override variable values. So the user can go set the values there when they run the job. We have an enhancement planned for version 5 so you can customize this some--for example, mark a variable as required so that the user will be forced to enter a value--but for now you need a workaround to make sure they enter something.

One way to do this would be to run a script as the first step of the job. If the job is being run manually, the script checks to make sure the variables have values, and fails the job if they don't. If the job is being run on a schedule, the script reads the file you mentioned to get the values.

You can use the "ADTTriggerClass" job variable to determine how the job is being run: for manual execution, this will be set to "Manual". Here's a sample VB script that you could run as step 1:


Imports System
Imports System.Collections.Generic
Imports ArcanaDevelopment.adTempus.Shared
Imports ArcanaDevelopment.adTempus.ApplicationIntegration

Public Class UserScript
    Inherits ArcanaDevelopment.adTempus.ApplicationIntegration.UserScriptBase

    Public Overrides Function Run() As Object

		If adTempus.JobVariables("ADTTriggerClass")="Manual" Then
			'job was triggered manually. Make sure StartDate and EndDate variables are set.
			If Not VariableHasValue("StartDate") OrElse Not VariableHasValue("EndDate") Then
				'one of the variables is not set. Log an error message and report failure so the job fails.
				adTempus.LogMessage(MessageTypeEnum.Error,0,"You must specify values for the StartDate and EndDate variables")
				Return 8
			Else
				'everything is OK. Report success
				Return 0
			End If
		Else
			'job is being run on schedule. Read a file to get the variable values
			SetVariablesFromFile
			Return 0
		
		End If
    End Function
	
	Private Function VariableHasValue(variableName As String) As Boolean
		Return Not String.IsNullOrEmpty(adTempus.JobVariables(variableName))
	End Function
	
	Private Sub SetVariablesFromFile()
		Using inputFile=System.IO.File.OpenText("c:\whatever.txt")
			'do whatever you need to get the values from the file
			
			'set the variables 
			adTempus.JobVariables("StartDate")="2017-01-01"
			adTempus.JobVariables("EndDate")="2017-01-31"
		End Using
	End Sub
End Class

You will need to modify the SetVariablesFromFile method to do whatever is appropriate to read the variables from the file.

Paul Watson (101 posts)
January 16, 2017 12:49 PM
Accepted Answer

This looks like a creative way to use the product. :-)

Is it possible to set the job variable back to NULL after the job completes? It needs to be undefined so that the user is required to enter the variable for the next manual run.

Does the setting of a variable (adTempus.JobVariables("StartDate")="2017-01-01") only set the variable for this instance, or does it change the setting for the adTempus job?

Bill Staff (599 posts)
January 16, 2017 01:03 PM
Accepted Answer
Variable values that the user sets in the execution options window, or that a script sets as illustrated, only affect the instance that they're set for. The value will be undefined for the next execution.
Paul Watson (101 posts)
January 16, 2017 01:25 PM
Accepted Answer

Where can I find the "execution options window?"

I am guessing that this is in the "Execute Job set_parameters" dialog box "Variables" tab. Is that correct?

Bill Staff (599 posts)
January 16, 2017 01:29 PM
Accepted Answer
Yes, it's the window that opens when you right-click a job and choose the Run command.
Paul Watson (101 posts)
January 16, 2017 01:58 PM
Accepted Answer
I notice that when I "Test" an adTempus shared script that it does not appear to be in "Manual" mode. Would that be a good default setting?
Bill Staff (599 posts)
January 16, 2017 02:22 PM
Accepted Answer

When you test a script, the system-generated variables that are set at runtime are not set, so there is no value for "ADTTriggerClass". The only way to test logic that depends on variables like this is either to set them yourself at the beginning of the script during testing, or run a test job that uses the script.

You could also check to see if the variable is empty using

string.IsNullOrEmpty(adTempus.JobVariables("ADTTriggerClass"))

This would tell you that the script is being run in test mode.

 

 

Replies are disabled for this topic.