Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

@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);

@Jaspal Singh  @Sandeep Rajput 

 

Thank you so much, now it's working as expected.

 

@srinidhi Please mark our answers correct if it has solved your issue. You can mark more than one answer as correct.

@Sandeep Rajput 

Yes I marked the answers.

 

Thanks.

 

Thanks a lot 🙂