How to pass variables from a powershell script back to the scratchpad

gregp
Kilo Contributor

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

5 REPLIES 5

Community Alums
Not applicable

If your PowerShell command returns something, you should be able to drop the output from it into a scratchpad variable by adding the following line to the Sensor script:



workflow.scratchpad.output = output;



Then you can reference it in other activities. If you want to parse out specific details from the output, you can then write some JavaScript to pull out the specifics you want from this output and put that information into other variables.


Thanks Ben,



Is there a way to perhaps read a small text file from the MID server into a scratchpad variable?   I'm not too familiar with JavaScript yet.   Is the Sensor Script able to run any valid JS command, or are there only certain functions supported?



thanks,


Greg


barbsies
Tera Expert

If output in the Sensor script doesn't work, try activity.output:



workflow.scratchpad.output = activity.output;



That's what we use.


gregp
Kilo Contributor

Thanks Barbara,



I was aware of the stdout variable, although I've not had a lot of luck with it.   I was actually trying to use that to capture any errors in the powershell activity in the workflow and write them to the RITM work notes.   However, I've not been able to capture more than the first couple lines of output, so I may be doing something wrong.   Is there a difference with sterr and stout in the Windows environment?



What I was hoping to do is to either be able to pass specific variables back from the PowerShell script into the scratchpad, or if that's not possible, can I read a file that exists on the MID server into a scratchpad variable?   Is there a list of all the valid commands I can place in the sensor script for a PowerShell activity?