Can you pass a on user demand workflow parameter into a script

We are looking to publish a workflow in ARS that will allow a user to input a parameter. The parameter would be a ServiceNow RITM number. We would like to pass that parameter to a powershell script inside the workflow. In the script we will query a log file using the RITM number.

Is this possible?

I see posts about going the other way, using scripts to set parameters in a workflow, like this one:

"Script format for defining Workflow parameter value"

When you create a notification in a workflow, you can modify the notification message and reference the parameters and include them in the message with this

Workflow.ParameterValue["Password"]

I'm looking for the equivalent of that for inside of a script. 

I have tried:

function onInit($context)
{

$param = $workflow.Parameter("TestParam")

$param2 = $context.Parameter("Password")

#Workflow.ParameterValue["Password"]

}

And this

function onPreCreate($Request)
{
$strClass = $Request.Class
if ($strClass -eq "user") {
$strPass = [string]$Context.Parameter("Password")
$strPass | Out-File '\\ServerName\c$\param2.txt'
}
}

Wanted to specific this would be for a "on user demand workflow"

Parents
  • Hello, please have look at the Active Roles SDK under the section "Retrieving data from workflow context". The script that runs within the Workflow can retrieve values set on Parameters via:

    $workflow.Parameter(name)

    Where (name) is the name given to the Parameter in the Workflow. No need to use the onInit function and name the function in your script a custom name and don't use one of the built-in event triggers like onPreModify for example.

Reply
  • Hello, please have look at the Active Roles SDK under the section "Retrieving data from workflow context". The script that runs within the Workflow can retrieve values set on Parameters via:

    $workflow.Parameter(name)

    Where (name) is the name given to the Parameter in the Workflow. No need to use the onInit function and name the function in your script a custom name and don't use one of the built-in event triggers like onPreModify for example.

Children