Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to save the data from the response body to one of the field in ServiceNow

srinidhi
Tera Guru

Hello Team,

 

Am able to see the response body but I need to fetch particular data from that and should update the field.

Please let me know further on this.

 

Thanks.

2 ACCEPTED SOLUTIONS

Better is to go with JSON.

Alternatively you can use below in background for a check.

var obj='{"data":{\"productId\":10868022,\"productName\":\"Locker 100 - Valid\",\"isMobile\":false,\"modifiedDate\":null,\"modifiedBy\":null,\"inactiveReason\":null,\"id\":117974,\"clientId\":1511,\"clientName\":\"\",\"locationId\":2623,\"locationName\":\", \",\"machineUserId\":1659531581,\"machineAccess\":\"0015984\",\"isActive\":true,\"clientTicketNumber\":\"SCTASK0015984\",\"createdDate\":\"2023-11-03T10:15:56.637\",\"createdBy\":\"srinidhi.munji\"}}';

var getproductid=obj.split('productId\"')[1];
var gegproductid2=getproductid.split(',\"productName\"')[0]
gs.print(gegproductid2);

 

View solution in original post

@srinidhi You can try the following.

 

var responseString="{\"data\":{\"productId\":10868022,\"productName\":\"Locker 100 - Valid\",\"isMobile\":false,\"modifiedDate\":null,\"modifiedBy\":null,\"inactiveReason\":null,\"id\":117974,\"clientId\":1511,\"clientName\":\"\",\"locationId\":2623,\"locationName\":\", \",\"machineUserId\":1659531581,\"machineAccess\":\"0015984\",\"isActive\":true,\"clientTicketNumber\":\"SCTASK0015984\",\"createdDate\":\"2023-11-03T10:15:56.637\",\"createdBy\":\"srinidhi.munji\"}}";
var responseObj= JSON.parse(responseString);
var product_id = responseObj.data.productId;
gs.info(product_id);

View solution in original post

9 REPLIES 9

Jaspal Singh
Mega Patron
Mega Patron

Hi,

Can you share the response body and what is to be fetched once.

Hello @Jaspal Singh ,

Thanks for the reply. Please find the response body below.

 

"{\"data\":{\"productId\":10868022,\"productName\":\"Locker 100 - Valid\",\"isMobile\":false,\"modifiedDate\":null,\"modifiedBy\":null,\"inactiveReason\":null,\"id\":117974,\"clientId\":1511,\"clientName\":\"\",\"locationId\":2623,\"locationName\":\", \",\"machineUserId\":1659531581,\"machineAccess\":\"0015984\",\"isActive\":true,\"clientTicketNumber\":\"SCTASK0015984\",\"createdDate\":\"2023-11-03T10:15:56.637\",\"createdBy\":\"srinidhi.munji\"}}"

I need get the Product id from the response.

 

Better is to go with JSON.

Alternatively you can use below in background for a check.

var obj='{"data":{\"productId\":10868022,\"productName\":\"Locker 100 - Valid\",\"isMobile\":false,\"modifiedDate\":null,\"modifiedBy\":null,\"inactiveReason\":null,\"id\":117974,\"clientId\":1511,\"clientName\":\"\",\"locationId\":2623,\"locationName\":\", \",\"machineUserId\":1659531581,\"machineAccess\":\"0015984\",\"isActive\":true,\"clientTicketNumber\":\"SCTASK0015984\",\"createdDate\":\"2023-11-03T10:15:56.637\",\"createdBy\":\"srinidhi.munji\"}}';

var getproductid=obj.split('productId\"')[1];
var gegproductid2=getproductid.split(',\"productName\"')[0]
gs.print(gegproductid2);

 

@Jaspal Singh  Checking on it.

Thanks