- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2021 01:54 AM
Hello Folks,
I'm new to service now. I'm trying to create a flow where the trigger is from an alert.
In the additional information of the alert, there is a key/value pair that I want to store as a variable and then use in an Action.
Additional info JSON:
{
name: "ashutosh",
id: "1234"
}
I want to extract the id and store it in a variable. Then, use that variable in an API call (action). If someone can provide me detailed steps as I'm very new to this platform would be nice.
Solved! Go to Solution.
- Labels:
-
flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2021 06:07 AM
Here is how I achieved it:
- In the sub-flow added an input variable and label as id of type string.
- In the action of rest API, I also created input variable and named it the same as the above.
- From the flow designer, there was an option to add a script, the key was very hard for me to find. I have highlighted the green box.
- After press that button, we need to add the below javascript code provided by
@Ankur Bawiskar . But we had to get to our records which were hard to find in the first line. Note: if you are trying to parse some other variable than additional_info, change it accordingly. Try to use auto-completion.
var str = fd_data.trigger.current.additional_info; var obj = JSON.parse(str); var id = obj.id; return id;
- Finally test the flow. It works like a charm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2021 03:08 AM
No worries.
Since your response has the detailed steps let us keep that as the correct answer so that future members can directly go through that and it would be beneficial to them.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2021 02:43 PM
This is a follow up to the original question posed by Ash (my teammate).
The Flow step that Ash authored becomes clearer if the Java Script entries, in the step inputs, are replaced with Data Pill variables that are extracted from JSON data, using the Service Now Out-of-the-Box Action "JSON Parser" (this is available for installation as part of a Subscription that includes the "ServiceNow Integration Hub Starter" entitlement).
I converted his Flow to a Subflow, which had a record as an input. Then, in an earlier Subflow step, I parsed JSON data, from a field in the triggering record, into individual variable values (Data Pills). In the step in question, I then replaced the Java Script, in the step input fields, with Data Pill variables. This has eliminated the need to know JavaScript when viewing or editing this Flow/Subflow. It also eliminated the relative "static" nature of Java Script, which had to identify a previous step number (and step numbers, if you modify a Flow or Subflow, will change, breaking your Java Script).
(An additional reason for converting this Flow to a Subflow - we want this logic triggered by our Alert Management Rules, since this is where all our Event Management "Alert triggers" currently reside.)
So, this Flow step used to look like this (input fields containing JavaScript):
The replacement Subflow, showing the same step, but with Data Pills replacing Java Script in the input fields: