Make the response wait for sometime from scripted rest API

Sadhana Mothe
Kilo Contributor

Hi

External interface is consuming our scripted rest API and posting a request.Our requirement is to wait for some time before sending response to external system,as have to wait for response from other external application and put that data in the API response and this may take sometime.

We have used gs.sleep before response.setBody but this is causing performance issue.

Any other best approach to achieve this is much appreciated.

8 REPLIES 8

Hi Alikutty, 
we are working on similar to this .
here is the scenario when sending the request from ServiceNow it's not in async, but response is taking time can you suggest some javascript for wait until response received.

thanks in advance.

srinivasthelu
Tera Guru

Hi Sadhana,



Synchronous is always wait, so performance hit..   No matter, which way you do, the client has to wait for the response until your system gets response from other system. timeouts!!!!..



Btw, what information you will need from the other system before you respond back to the client? , Can you maintain a copy of it, per say, a schedule refresh every 30 mins.



So that, you can just respond back to the client system by reading the copy from your system itself.




Thanks


Srinivas


Hi Srinivas,



Below is the flow in which the final response is sent to external system



  • External interface(IVR) consumes our Scripted rest API and post a JSON request.
  • Scripted Rest API will trigger a workflow with inputs derived from the above JSON request.
  • The workflow has an activity which post a request to rest endpoint(other system) and parse the response.
  • This response will differ based on the input given to workflow(which is from IVR).If we store the information also it will be different for different transaction.
  • Once we parse the response, we have to send few JSON parameters values in response body to IVR.
  • As the above process take sometime we want to have a wait for few seconds before triggering the response.


Thanks,


Sadhana


Hello,


I need to create a Webservice API where input is: Sys ID of any record and output is: all *related* active records to that sys id. The relationships between the tables is maintained in Relationships under system definition.


Could you please guide me how to implement this? Sample code would be great.


Input: Sys ID of the record
Output: All *RELATED* active records from *VARIOUS* tables (in the following JSON format):
{
"result": [
{
"Sys ID": "5520267",
"CI Name": "Record 1",
"Table Name": "u_table_a"
},
{
"Sys ID": "5520367",
"CI Name": "Record 2",
"Table Name": "u_table_a"
},
{
"Sys ID": "8331210",
"CI Name": "Record 1",
"Table Name": "u_table_b"
},
{
"Sys ID": "8321210",
"CI Name": "Record 2",
"Table Name": "u_table_b"
},
{
"Sys ID": "3042006",
"CI Name": "Record 3",
"Table Name": "u_table_b"
},
{
"Sys ID": "4509847",
"CI Name": "Record 1",
"Table Name": ""u_table_c"
}
{
"Sys ID": "4509247",
"CI Name": "Record 2",
"Table Name": ""u_table_c"
}
]
}