Need to get value from Array Object

Bird1
Mega Sage

Hello,

 

Can anyone please help? In Flow Designer, when I called API, I got Response Body as below data. It's Array Object type. I would like to get the "value" of emails data (test@abc.com). in String. Which script can help?

 

 

 

"emails":[
        {"value":"test@abc.com",
        "type":"work",
        "primary":true}
        ],

 

 

1 ACCEPTED SOLUTION

Vasantharajan N
Giga Sage
Giga Sage

@Bird1 - I assume the response is JSON and the below script will parse the object and set the value (key) to the variable email which you can set it to output variable of your flow action. 

var responseContent = {
"emails": [{
    "value": "test@abc.com",
    "type": "work",
    "primary": true
}]
};

var email = responseContent.emails[0].value

Thanks & Regards,
Vasanth

View solution in original post

4 REPLIES 4

GopikaP
Mega Sage

Hi @Bird1, if there is only one child inside the object you can store the value in a flow variable and then use it - 

var email = fd_data.subflow_inputs.emails[0].email.toString();
gs.log("Email = "+email);
fd_data.flow_var.email = email;

I utilized a subflow to replicate your requirement.

If there will be more than one child, then call a for each inside the flow, then pass the value:SC.png

@GopikaP - Thank you very much!

Vasantharajan N
Giga Sage
Giga Sage

@Bird1 - I assume the response is JSON and the below script will parse the object and set the value (key) to the variable email which you can set it to output variable of your flow action. 

var responseContent = {
"emails": [{
    "value": "test@abc.com",
    "type": "work",
    "primary": true
}]
};

var email = responseContent.emails[0].value

Thanks & Regards,
Vasanth

@Vasantharajan N - Thank you very much!