Page History
Table of Contents |
---|
Introduction
- Users frequently find the situation when a business date has to be made available to a larger number of jobs.
- This can include the current date or a calculated date such as a trade date that considers calendars.
- This can include a previous date such as a reporting date.
- Requirements
- The business date has to consider existing business rules, e.g. to use the current date, a calculated date or a previous date.
- The business date has to be updated at a precise point in time and on a regular basis.
- The business date has to be made available to a larger number of jobs.
Building Blocks
Use of Job Resources
JS7 - Job Resources are a means to carry variables and to make them available to jobs.
...
The Job Resource can be configured with the "Arguments" tab like this:
- an argument with the name
businessDate
is introduced that holds an arbitrary a business date value that later on will be updated automatically.
For the same Job Resource switch to the tab "Environment Variables" to complete the configuration like this:
...
Then deploy the above Job Resource.
Use with Jobs
Environment variables from Job Resources are automatically available for job scripts.
- For jobs executed with Unix Agents the environment variable is available from its name, e.g.
$BUSINESS_DATE
. - For jobs executed with Windows Agents the environment variable is available from the syntax
%BUSINESS_DATE%
.
Job for Unix
Download for Unix: pduVariableBusinessDateGet.workflow.json
The job is assigned the Job Resource with the given name. In the job script the environment variable $BUSINESS_DATE
is used that is available from the Job Resource.
Job for Windows
Download for Windows: pdwVariableBusinessDateGet.workflow.json
The job is assigned the Job Resource with the given name. In the job script the environment variable %BUSINESS_DATE%
is used that is available from the Job Resource.
Updating the Business Date
The preferable approach is to update the value of a global variable such as a BusinessDate
, the global businessDate
variable by a job.
- Users can create a workflow with a single job that updates the
BusinessDate
, environment variablebusinessDate
variable. - This job The workflow is triggered by a order
...
- an order from JS7 - Schedules to switch the business date for example at midnight in the respective time zone and for specific days.
Job for Unix
Download: pduVariableBusinessDateSet.workflow.json
Example how to update a business date from a PowerShell job script
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/usr/bin/env pwsh # Adjust the path to your Job Resource $jobResourcePath = '/ProductDemo/Variables/pdBusinessDate' # Consider to use the appropriate URL that matches host and port of the JOC Cockpit instance $url = "http://localhostjoc-2-0-primary:4446" # Consider to store credentials with a PowerShell profile or with a credential store or to use certificate based authentication as an alternative to user/password $credential$credentials = ( New-Object -typename System.Management.Automation.PSCredential -ArgumentList '"root'", ( '"root'" | ConvertTo-SecureString -AsPlainText -Force) ) # Consider the identification of the Controller that the job resource should be deployed to $controllerId = "testsuite" Import-Module JS7 Connect-JS7 -Url $url -Credential $credentialid $env:CONTROLLER_ID -IdCredentials $controllerId$credentials $jobResource = Get-JS7InventoryItem -Path /Defaults/DailyDefault$jobResourcePath -Type JOBRESOURCE if ( $jobResource.arguments.BusinessDate ) { # update the business date $jobResource.arguments.BusinessDate = (Get-Date -Format "yyyy-MM-dd") } else { # add a business date variable to the Job Resource $jobResource.arguments | Add-Member -Membertype NoteProperty -Name BusinessDate -Value (Get-Date -Format "yyyy-MM-dd") } # Update and deploy the Job Resource Set-JS7InventoryItem -Path /Defaults/DailyDefault$jobResourcePath -Type JOBRESOURCE -Object $jobResource Publish-JS7DeployableItem -Path /Defaults/DailyDefault$jobResourcePath -Type JOBRESOURCE -ControllerID $controllerId$env:CONTROLLER_ID Disconnect-JS7 |
Job for Windows
Download: pdwVariableBusinessDateSet.workflow.json
For Windows use the above PowerShell script code from the above Unix example except for the first line (that indicates a shebang) that should be replaced bylike this:
Code Block | ||
---|---|---|
| ||
@@findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof |
...