- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 10:08 PM
I have cloned the "Create Incident" Sub-Flow. Note that this is a SubFlow not a flow. I am now modifying the Activity called: "Create Task". I have added "Location" down the bottom. This is a field that the SolarWindows team would like to populate on the incident. I know I should use the CMDB. But they have already included this info into the SNMP TRAP. The Network Team are quite insistent. The Location information from the TRAP appears in the alert in the Additional Data (additional_info) field. I therefore want to extract the SWD_Location field from the JSON of the Additional Data and then set the Location Field on the incident.
The SN documentation does not say anywhere how to access these input variables for a SubFlow. When you first create the script, the ServiceNow default script contains comments that explain how to do it for a Flow - but not a Subflow. (The comments mention the trigger.current but there is no trigger.current record for my Subflow. Maybe I am confused - but I am have tried Trial and Error. I have exhausted all attempts at Googling. Any thoughts anyone? Thank you in advance.
Here is my Code
/* 2020-05-14 Doug Connell This code is designed to fill in the Location field on the incident. using the addititional data field from the alert. The Additional Data Field is in JSON format. */ var logMessage = ""; var additionalDataString = inputs.alertGR.additional_info.toString(); logMessage += "\n inputs.keys()=" + inputs.keys(); logMessage += "\n inputs.alertGR.sys_id=" + inputs.alertGR.sys_id; logMessage += "\n inputs.alertGR=" + inputs.alertGR; logMessage += "\n inputs.ah_alertgr.sys_id=" + inputs.ah_alertgr.sys_id; logMessage += "\n inputs.ah_alertgr=" + inputs.ah_alertgr; logMessage += "\n ===== Additional Data =====\n" + additionalDataString + "\n ==========\n"; var additionalDataObject = {}; var location = ""; try { additionalDataObject = JSON.parse(additionalDataString); location = additionalDataObject.SWD_Location; logMessage += "\n Setting location to: " + location; } catch(err) { location = ""; logMessage += "\n Parsing the JSON failed!"; } // Setting the source of the System Log message to "SW" (SolarWinds) so that it is easier to find. // NOTE: Don't forget to comment this gs.log line below after you have fnished debugging. gs.log(logMessage,"SW"); return location;
This is the output I get in the System Log:
nputs.keys()=undefined inputs.alertGR.sys_id=undefined inputs.alertGR=undefined inputs.ah_alertgr.sys_id=undefined inputs.ah_alertgr=undefined ===== Additional Data ===== undefined ========== Parsing the JSON failed!
Testing
I am testing using the Test Button at the top of the Subflow. I am entering a valid alertGR record. So I can see that it is set in the Executions record. Maybe inputs are not part of the inputs object? Maybe it is called something else - maybe input or my_inputs? Maybe I have to create a custom Activity? I am in the dark and guessing.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 11:53 PM
Yes. I tried fd_data. It didn't work. I suspect that fd_data works for Flows not Sb-Flows - but i am still learning.
However I did get it working.
- I copied the Activity called: Calculate Values (Based On The Alert). I created my own custom Activity called: Calculate Values (Based On The Alert).
- I then modified this new custom activity so that it had only one input variable (alertGr) and one output variable (location). I changed the code so that it did the JSON.parse of the Additional Data field and returned the location.
- I then linked this new Activity into my SubFlow. I made sure I put it as a Step before Create Task.
- Lastly editing the Create Task Activity in my Subflow to set the location field as a new Field Value step right at the bottom. This step now required no code. It just used the referenced variables that you access using that Black Bullet/Spanner Icon.
So my fist method should have worked. I don't know why it didn't. However, I managed to get it working - even through this method is longer and more involved. so I am moving on ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 11:56 PM
One of the things that I am still confused about though - is that my Update Set was in the Global scope. When I copied everything, it all moved into the Global Scope - even though the items that I copied exist in the "Alert Management Content" scope. So my Update Set should be OK ... but ....
Which scope should I have used? Should I redo my Update Set using this custom scope? What is best practice?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 07:52 AM
The right way to access the input variables is with:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2021 06:58 AM
Thanks Frank,
That syntax is what was missing when trying to access the info from the case that was passed to the workflow.
I needed to use 'fd_data.subflow_inputs.case' where case is the name of the input, and then you can dot walk to the fields from there.
Shannon

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2021 07:10 AM
Awesome, Shannon. I'm glad the information was helpful.
Frank

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 03:57 AM
the subflow_inputs variable doesn't comeup in auto-suggestion. Is that true?