Versions Compared

Key

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

Workflow scripts allow you to perform actions programmatically on one or multiple objects within RED. For example, you can create a workflow script that exports the DDL for one or multiple objects or for performing to perform GIT operations like Check-in or Check-out on a set of objects. You can launch scripts from the context menu of one or multiple selected objects.

Note
titleNote

 The Workflow context menu only shows when you have created a Workflow Host Script Language.

Adding a Workflow script

This section provides examples on of how to create Workflow scripts.

Before Creating a Workflow script, you first need to add a Workflow Workflow host script language type. For instructions on adding a new language type refer to Adding a Host Script Language Type

...

Code Block
languagepowershell
titlePrint Context
collapsetrue
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. ***"
}

...

To check the output files, go the temp folderto your working directory.


Tip
titleScript Samples

For more script samples refer to the Workflow Script Samples section.