The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Asynchronous call between REST API and Script Include

Rob Bushrod
Tera Guru

Hi All,

I am trying to set up a REST API to create a catalog item based on a value within the received payload; New user, Update User, Disable Account.

Part of the requirement is to send back to the 3rd party system that is raising the request, the sys_id and reference number of one of the tasks that is being created from the workflow. This was being achieved by calling a script include that is checking the sc_task table for a task that is associated to the RITM and has a particular assignment group. This was working fine in dev but when promoted to production kept returning an empty result. 

On investigation by ServiceNow for why no value was being returned in prod but being returned in dev the answer was that it shouldn't really be working in dev as the the timing means I'm querying for a uncommitted/partially committed record. Their advise was to try and run it asynchronously so that the request item and tasks are fully committed.

I have been working on this today but can't seem to get it right as the script messages keep giving me a yellow '!' about the new function being in the wrong place when trying to create a GlideAjax function. 

 

Any suggestions gratefully received, attached is the code from the section of the scripted REST API and the script include where I am trying to do the log up. The commented out section was the original with the new functions above.

 

Rob

6 REPLIES 6

Hi @ashishdevsingh,

I am trying to send the information in the response to the original message sent from 3rd party system. 

Many Thanks,

Rob

Hi @Rob Bushrod ,

 

Then you test one scenario, since you are creating the the responseBody after creating the new item, you can test it while using gs.sleep(5) then check if you are able to get the record value. 

or you have information already while creating the record, only you need number and sysID, so i think it is generated before the database operation is successful. so try to capture that info and create responseBody. Let me know if it works or not.