Recommended way to implement asynchronous outbound REST call with MID Server

ktsuda
Kilo Contributor

I am creating the workflow implementing Outbound REST call with MID Server and would like this call be truly asynchronouse(means the workflow will exit without waiting a reply from the REST call).

According to the article below, It seems possible to implement this requirement using the ServiceNow's "Discovery probe and sensor" feature. (final example in the article)

https://hi.service-now.com/kb_view.do?sysparm_article=KB0694711

My question is regarding this solution. Do you think it is a recommended way to implement truly asynchronous?

I understand the "Discovery probe and sensor" feature is for finding an IT resources in the environment to manage and not for creating a custom logic like business rule or workflow. so I feel this solution might be too tricky to use in production environment.

Please give me your comment about this. and if you have more sophisticated way to implement truly asynchronous, please let me know.

Thanks in advance.

 

3 REPLIES 3

Patrick DeCarl1
ServiceNow Employee
ServiceNow Employee

 

 

I would not use the discovery probe. You can do all this via the RESTmessagev2 api. You can create a rest message record, use thw workflow to call message. In that record you can pick what mid server you want to use, in the record, it will give you the script to use. 

 

https://docs.servicenow.com/bundle/newyork-application-development/page/integrate/outbound-rest/task...


ktsuda
Kilo Contributor

I have already used a REST Message with MID Server. Would you please tell me which property can I use to register my call back procedure (or some script like business rule)?

There is no property. You would use code like below to make the call and to see the return. 

 

 try { 
 var r = new sn_ws.RESTMessageV2('Rest Message', 'The method');
 r.setStringParameterNoEscape('pagesize', '500');
 r.setStringParameterNoEscape('page', '0');
 r.setStringParameterNoEscape('ownership', 'C');

//override authentication profile 
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);

//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');  <-- if you want to change mid server

//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
r.setEccParameter('skip_sensor', true);   <-- Use this to skip the sensor

 var response = r.execute();
 var responseBody = response.getBody();  <-- Here you need to parse the body to get your data. 
 var httpStatus = response.getStatusCode();
}
catch(ex) {
 var message = ex.message;
}