Page History
...
- Create a language type called ps workflow
- Set the file extension to ps1
- Set the command to PowerShell -ExecutionPolicy Bypass -File "$SCRIPT_NAME$"
- Set the category field to Workflow.
- Click OK.
- Add a new Metadata Object Type.
- To add a new object, right click on the Host Script node.
- Select New Object.
- For this example, enter Print Context as a name.
- Click OK.
- In the configuration window, set the type to ps workflow script, set the appropriate Owner and Connection Name for your data.
- The new script should appear on the Host Script node.
- Right click on Print Context and select Edit the Script. This will open the script on a new tab.
- On the edit script tab enter the following code:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
write-output 1
write-output 'Printing context'
# print the expected context file
write-output "---- Parsing context file: `n$PSScriptRoot\wsla${ENV:WSL_SEQUENCE}.objects"
if (Test-Path -path "$PSScriptRoot\wsla${ENV:WSL_SEQUENCE}.objects") {
# Parse json .objects file
$json = Get-Content "$PSScriptRoot\wsla${ENV:WSL_SEQUENCE}.objects" | Out-String | ConvertFrom-Json
# Context
write-output "`n---- Context: $($json.context)"
# Group
if ($json.group -ne $null) {
write-output "---- Group: $($json.group)"
}
# Projects
if ($json.project -ne $null) {
write-output "---- Project(s):"
$json.project
}
# Objects
if ($json.objectsByName -ne $null) {
# print objects
$htRedObjects = [ordered]@{}
# Populates a hastable with obj-name as Key and obj-type as Value from RED formatted json
$json.objectsByName | get-member -type properties | %{ $htRedObjects[$_.name] = $json.objectsByName."$($_.name)".objectType.name }
$htRedObjects.Keys | select @{label='Object Name';expression={$_}}, @{label='Object Type';expression={$htRedObjects.$_}}
}
# Jobs
if ($json.jobsByName -ne $null) {
# print jobs
write-output "`n---- Jobs:"
$redJobs=@()
$redJobs = $json.jobsByName
$redJobs
}
# Parameters
if ($json.parametersByName -ne $null) {
# print parameters
write-output "`n---- Parameters:"
$redParams=@()
$redParams = $json.parametersByName
$redParams
}
}
else {
write-output "*** Error: Objects file doesn't exist as there were no objects in the current context. ***"
} |
Running the Script
To run the script, right click on an object, go to Workflows, and select Print Context.
...