
i have a requirement that i'm caling API from flow. From that I'm passing response back to js. That result I'm storing in ja variable.
Now I'm able to get complete result. but while I'm trying to extract particular value from result getting undefined.
Please refer screen shot attached there I'm showing result array in alert.
var result = this.response;
alert("" + result);
var vendor=result["Vendor"];
alert(vendor);
code snippet.
Please help me to achieve this.
Hi,
Thank you for your query.
I believe the response is in JSON (not an array).
You need to pars it as JSON using JSON.parse function.
Here is the sample code for your reference:
var responseText = '{"Entry_Sheet":1234,"Vendor":"000011"}';
var jsonObj = JSON.parse(responseText);
console.log(jsonObj.Vendor);
An if the response is a JSON Array (starts with [), look at following example:
var responseText = '[{"Entry_Sheet":1234,"Vendor":"000011"}]';
var jsonObj = JSON.parse(responseText);
// Read the object using array index
console.log(jsonObj[0].Vendor);