Response to Scripted REST API Payload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 08:40 AM
Hi All,
I have created a staging table using web service for my ServiceNow Integrtion. Created below Scripted Rest API to receive the payload from a third party. It should create an incident using a staging table and respond to the Incident number in the response body. I am trying to capture the payload data into the staging table and create an incident using a transform map. There seems delay in b/w two entries and it is not responding to the incident number in the response body. But when I compare the created date/time there is no delay. Not sure I am missing something here. Here is my Scripted API code. Can someone help with this?
=============================================
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 09:14 AM
It's a bit weird to use scripted rest api and then a staging table. What are your coalesce fields there?
Could you not just first query a incident and if none is found then create a new one directly in the scripted rest api?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 09:31 AM
Hi
I have created a correlation ID in the transform map which will hold the customer's "incident number". So next time if it finds the same number then it will update the staging table and the same will be reflected in the corresponding incident which is working fine.
I am not querying the incident. It depends on the staging table entry. If new record then it will create a new incident else will be updated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 02:12 AM
But you could do it directly in the scripted rest API as well.
query for the correlation ID value. If found, update, else insert.
If you're using a staging table, you could just tell the other party to send the rest message there?
If you really want to use the staging table and can't have the 3rd party send a message there then you could perhaps create outbound rest API for your instance itself. It's a bit of unnecessary extra compared to the first option I gave, but that way when you send the rest message your script will continue after a response has been received. The response would contain the target sys_id which you could then return.
This would also allow you to filter out stuff in the scripted rest api if you don't want to let everything through.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 09:34 AM
Hi @balaji_prusty1
Please check if these can help.
How to make use of gs.sleep() in a scoped application scripts
Mark Correct and Helpful if it helps.
***Mark Correct or Helpful if it helps.***