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

Amit Verma
Kilo Patron
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


Please mark this response as correct and helpful if it assisted you with your question.

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

Amit Verma
Kilo Patron
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;

 

 

 

 

 

 

 


Please mark this response as correct and helpful if it assisted you with your question.