Inbound REST, JSON as a field value

Jamsta1912
Tera Guru

Hello all,

I'm working on a system integration with a third party. I have created a web service and transform map in our DEV instance, and we're able to receive and process inbound POSTs with bodies like this:

{
"u_number":"INC7654521",
"u_location":"HQ",
"u_cmdb_ci":"Toaster"
}

However, the third party would like to standardise their outbound messages to have bodies like this:

{
"incident":{
"u_number":"INC7654521",
"u_location":"HQ",
"u_cmdb_ci":"Toaster"
}
}

So, the JSON in my first example itself becomes the value of a field called "incident" in my second example. This doesn't work for the web service I've created, which has field names 'u_number', 'u_location, and 'u_cmdb_ci', and I guess in the second example the message is 'looking for' a field named 'incident'. 

What are my options for processing the inbound message in the second case? I'm thinking I may have to write a script to place each inner field value onto the input row to trigger the transform map, but I would like to know what ya'll think.

Jamie.

1 ACCEPTED SOLUTION

You can construct the response body in the Scripted rest api script as below

 

var body = {};
body.name = "incident";
body.number = "1234";
body.caller = {"id": "user1"};
response.setBody(body);

reference: https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

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

View solution in original post

12 REPLIES 12

If you are storing the 3rd party ticket number in the incident record, you can query by the 3rd party reference number and send it back in response


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

Thank you. That worked. My concern was that the Glide lookup would be trying to find the new record before it had been created, but I guess it's the case that all activities associated with the import set table and transform map are completed before the script moves on to the next line - ie it's synchronous.

Great. Can you mark it answered so that it will be helpful for others in future.


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