Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Updating the Business Date

The final task includes to update the business date at a regular basis. This is achieved by use of the JS7 - REST Web Service API.

  • The JS7 REST Web Service API is available for any scripting languages and programming languages that implement a REST client.
  • This allows to set the business date from an individual application that triggers the date change.
  • This allows to set the business date automatically from a JS7 job.

The proposed preferable approach is to update the value of the global businessDate variable by a job.

...

Download: pduVariableBusinessDateSet.workflow.json

Example how The job example to update a business date from a PowerShell job scriptmakes use of a PowerShell job script and the JS7 - PowerShell Module.

  • The JS7 PowerShell Module is a wrapper for the JS7 - REST Web Service API.
  • The JS7 REST Web Service API can be used with any other scripting language such as Perl, Python, Ruby etc.

Image Added


The job performs the following operations:

  • connect to JOC Cockpit by use of the Connect-JS7 cmdlet.
  • read the Job Resource by use of the Get-JS7InventoryItem cmdlet.
  • update the businessDate variable to the current date and specify the desired date format.
  • store the updated businessDate variable to the Job Resource by use of the Set-JS7InventoryItem cmdlet.
  • deploy the updated Job Resource by use of the Publish-JS7DeployableItem cmdlet.
  • disconnect from JS7 by use of the Disconnect-JS7 cmdlet.

Code Block
languagepowershell
titlePowerShell implementation to update the business date with a Job Resource variable
linenumberstrue
#!/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://joc-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
$credentials = ( New-Object -typename System.Management.Automation.PSCredential -ArgumentList "root", ( "root" | ConvertTo-SecureString -AsPlainText -Force) )


Import-Module JS7
Connect-JS7 -Url $url -id $env:CONTROLLER_ID -Credentials $credentials

$jobResource = Get-JS7InventoryItem -Path $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 $jobResourcePath -Type JOBRESOURCE -Object $jobResource
Publish-JS7DeployableItem -Path $jobResourcePath -Type JOBRESOURCE -ControllerID $env:CONTROLLER_ID

Disconnect-JS7

...

Download: pdwVariableBusinessDateSet.workflow.json

For Windows use the The job includes the same PowerShell script code from and performs the same operations as the above Unix example except for the first line (that indicates a shebang) that should be replaced like this:

...

job example.

The only difference of the Windows job is use of shebang that is specific for this OS.

...

  • Consider use of the following shebang in the first line of the job script:

  • @@findstr/v

...

  • "^@@f.*&"

...

  • "%~f0"|pwsh.exe

...

Image Added

Schedule for automated job execution

To automate the execution of the JS7 workflow in order to update the business date users can create JS7 - Schedules that generate orders for execution at a given point in time.

Download: pdsVariableBusinessDateSet.schedule.json

A schedule is created like this:

  • The schedule references the workflow to be executed.
  • The schedule is specified to be planned and to be submitted automatically to the JS7 - Daily Plan

Image Added


To specify the point in time of workflow execution the schedule is added a run-time setting like this: 

  • A calendar is assigned that specifies the days for which the workflow is executed.
  • A period is assigned that specifies the hour, minute and second for start of the workflow.

Image Added