How to parse response in workflow runscript
This content was last updated in 2024. It may still be useful, but could contain outdated information. Please confirm its accuracy before relying on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 04:54 AM
Hi Team,
I am working on one integration where first api generate a Machine Number and I need to parse it from the response and call send that machine number in the second api.
Response Body{"data":{"modifiedBy":null,"customData":{""machineAccessNumber":"2794"}
Code in 1st API to parse machineAccessNumber
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 05:56 AM
Does the Response Body really have two quotes before machineAccessNumber? If it does, that's the first problem. I assume the Response Body also continues from what is shown to close all of the curly brackets }}
Since some of the object values are themselves objects, you need to drill-down when accessing a nested value, and use the same name as in the Response Body (yours is missing an 'e' at the end of machine)
var ipin=parseData.data.customData.machineAccessNumber;
Once you get the correct value for 'ipin' I assume you are also setting this to the value of workflow.scratchpad.ipin, to use in the later workflow activity for the 2nd API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 01:29 AM
Hi Brad,
Yes I am getting value in first API AFTER adding data in the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 03:06 AM
Scratchpad is the right idea when using a variable in more than one Run Script activity. Now that you have a good value for pin1, either add another line to assign the value to a new scratchpad variable, or if you are not using 'pin1' anywhere in the same script, change the assignment to a scratchpad variable.
var pin1=parseData.data.machineAccessNumber;
workflow.scratchpad.pin1 = pin1;
-or-
workflow.scratchpad.pin1 = parseData.data.machineAccessNumber;
Then in the other Run Script you will be able to access workflow.scratchpad.pin1 as you attempted.