How do I pass a powershell variable to orchestration workflow?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 08:43 PM
Hi All
We are moving from MS System Center to ServiceNow for ITSM. At the moment I am trying to get my head around the orchestration in SN, which unfortunately is quite a bit more difficult than it was in SCOrch
For now - I am trying to take the value of a variable in a custom powershell activity and then use it throughout the rest of the workflow. In this case, it is a username that has been generated to policy via a PS script from the first and last name of the user - eg.
Firstname = John
Lastname = Smith
results in
$Username= jsmi1
I need to take that $username value and then use it to create a new AD user.
When i am in the custom PS activity and do "test inputs" - it works without issue. Output shows the value i want. In the custom PS activity, I created a parsing rule to take the value of the activity.output and map it to output1
In the workflow, i added a script activity to take the results and put them in the scratchpad using
workflow.scratchpad.username = data.get(7).Output1 (which is from the little data navigator thingy)
then I put a notification activity to send me an email with ${workflow.scratchpad.username} in it - so i can validate what it's doing.
This email does not have the data in it. It just gives me "..sc1". If i add the "${data.get(7).Output1}" to it also - that does nothing.
I have tried ending the PS script with a few different ways of displaying the data to see if it changes anything, nothing helps. So far i have tried
{script goes here that sets up $username variable}
$username (to just output the username)
and
write-host $username
and
$data = $username | ConvertTo-JSON
write-host $data
and currently
Write-Output "%%out_data1%%"
Write-Output "$($username)"
Write-Output "%%"
and then parsed the output1 varible to the out_data1 tag as shown in the attachment.
This is super basic stuff in scorch but it's killing me in servicenow. what am I doing wrong?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 09:55 PM
Hi Kai,
Please refer the link below.
https://community.servicenow.com/community?id=community_question&sys_id=7a8e8b21dbdcdbc01dcaf3231f9619c6
If that is the output of an activity then you can use activity.output.
Hope this helps.
Regards
Ujjawal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2018 06:19 PM
thanks for the response.
Looks like they are using tags to get the value, which is what i am currently doing. It's just not working for me. Some of the other stuff they are talking about is quite hard to follow, i'll have to do some further research.
If anyone from ServiceNow is reading this - a suggestion for the next build might be to simplify powershell integration!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 11:17 PM
Hi
In general, $ symbol is used for declaring a variable and $_ symbol is used for accessing the attributes of the element currently used. Similar to our "current" and we have used something similar it worked fine. Simply, we have to pass the variables.
Please mark as helpful or correct based on my response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2018 06:09 PM
Thanks for the response.
I'm familiar with variables inside powershell, and the PS code is fine. I just need to learn how to take the contents of a PS variable and pass it to another activity in a ServiceNow workflow.