Getting sys id of the incident created through scripted rest api and script include

Arti Kumar
Tera Contributor

I have written a scripted rest api that calls a script include.

The script include has a function that uses insert() to insert a record in a staging table.

An inbound web service takes this record and runs it through the transform map to POST in the incident table

 

Can anyone suggest how to render the sys id of the incident posted in the system table in the response body of the scripted rest API?

Currently the incident gets posted correctly but the response body is empty

2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, with the structure identified in your post there is no direct relationship between the initial REST insert and the result of the transform map, IE the created task, as this does not happen synchronously. To resolve this, you would need to insert the target record as part of your scripted rest api and not as part of a subsequent transform.
But, personally I believe that this async process is the most appropriate\best practice way to insert records via integration and it greatly reduces the changes of the integration causing degraded performance.
The best solution would be to send the resulting sys_id as an update post record insert, rather than as a response to the initial POST.
Another (less optimal) alternative would be to generate a partial\empty target record as part of the scripted rest api and then populate the details into this 'shell' record using the import\transform process as an 'update',

so the record is created allowing you to return your sys_id but the heavy work is still managed by an import\transform meaning there is a reduced risk to your instance.

 

 

Arti Kumar
Tera Contributor

Thanks Tony. This makes sense.

Although I realized that the client I am integrating with would need the sys id of the intermediate record not the final target task. So I am providing that in the response for them to be able to post updates in our instance. I was able to add it to the response using getUniqueValue() post insert().

I DO need to provide the INC number of the target record created as well, so would be using an 'update' post record insert as you suggested