Fetching object from Response Body in flow designer

Ujjwal1
Tera Contributor

hi all,

I am using Flow Designer  and  inside that Flow Action is called. Output of Flow Action is JSON (Response Body)

{"ObPrivateID":"61603","ObCityID":"86af8877c919712c332b3d47f3a01280b43756a","cacheKey":null,"errorCode":null,"errorMessage":null,"hasError":false}

 

Need to fetch ObPrivateID from response body and assign that value(61603) to a field , in Flow designer.

 

Please suggest.

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hello @Ujjwal1 

Are you returning the entire object from the action?

You can try something like in script step and access the object in that and return only the ObPrivateID from outputs.

 

var ob = {
    "ObPrivateID": "61603",
    "ObCityID": "86af8877c919712c332b3d47f3a01280b43756a",
    "cacheKey": null,
    "errorCode": null,
    "errorMessage": null,
    "hasError": false
};
var obStr = JSON.stringify(ob);
var obPar = JSON.parse(obStr);
gs.info(obPar.ObPrivateID);  //61603

 

Hope it helps:)

 

Thanks,
Murthy

View solution in original post

3 REPLIES 3

vermaamit16
Kilo Patron

Hi @Ujjwal1 

 

You can either make use of JSON parser step https://docs.servicenow.com/bundle/washingtondc-integrate-applications/page/administer/flow-designer...

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

Murthy Ch
Giga Sage

Hello @Ujjwal1 

Are you returning the entire object from the action?

You can try something like in script step and access the object in that and return only the ObPrivateID from outputs.

 

var ob = {
    "ObPrivateID": "61603",
    "ObCityID": "86af8877c919712c332b3d47f3a01280b43756a",
    "cacheKey": null,
    "errorCode": null,
    "errorMessage": null,
    "hasError": false
};
var obStr = JSON.stringify(ob);
var obPar = JSON.parse(obStr);
gs.info(obPar.ObPrivateID);  //61603

 

Hope it helps:)

 

Thanks,
Murthy

vermaamit16
Kilo Patron

@Ujjwal1 

 

Alternatively, you can make use of below code in the variable you want to set to parse and set the JSON value :

 

var keys= JSON.parse(inputJSON); // Please replace inputJSON with your variable
var id = keys.<your key>; //Replace key with your JSON key
return id;

 

 

 

 

 

 

 

Thanks and Regards
Amit Verma