How to pass variables from a powershell script back to the scratchpad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2015 04:37 PM
Hello,
I am running a custom powershell script in a "run powershell" activity.
I have my script in the 'command' window of the activity. In that script, I can pass variables that are already in the scratchpad from a prior activity into the script's variables, e.g.:
$CompanyName="${workflow.scratchpad.CGA_company_name}";
This works fine.
However, after the script runs on the MID server, it has data I want to pass back to the scratchpad so I can write it to the comments field on the RITM.
I've tried doing the reverse of the above, but that throws a syntax error.
I've also tried adding a line similar to the following in the "sensor script" box:
workflow.scratchpad.current_error = $body_text;
But that errors out as well. Does anyone know how to do this?
Best regards,
Greg
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2015 02:06 PM
To get data from my Run PowerShell activity back into my workflow I do the following:
At the end of the PowerShell code, once your payload is created use these three lines:
Write-Output "%output%" #the % signs are required; the text can be anything you want
Write-Output "$($payload_variable_name)" #whatever variable name you used for your payload
Write-Output "%%" #again the % signs are required
In the Sensor Script you will read the "tags" sent by the PowerShell script. The tag is whatever text you put in the first line, so:
var ps_output = tags.output
From there you can parse it as necessary. This works really well for regular text and JSON from PowerShell.
Hope this helps,
Chad