Business rule and REST

argho
Kilo Contributor

Hi there,

I am very new to Service NOW. I was trying to accomplish that every time an incident is created, I send a REST post request to an external server. I tried to follow the guide https://express.servicenow.com/support/videos/servicenow-express-outbound-rest/

So I have my outbound rest call defined and tested and that works fine:

Untitled.png

But once I try to create a business rule ( I do this as the admin user), something weird happens, the web tab appears but shortly after the page has loaded the tab disappears...

When opening the page:

find_real_file.png

After loading is completed:

find_real_file.png

So then I tried with the Advanced option and added the code I retrieved from the outbound section, it looks like this:

try {

var r = new sn_ws.RESTMessageV2('Change record', 'UPDATE EXTERNALLY');

r.setStringParameterNoEscape('close_date', current.resolved_at);

r.setStringParameterNoEscape('INCIDENT_NUMBER', current.number);

r.setStringParameterNoEscape('inc_id', current.number);

//override authentication profile

//authentication type ='basic'/ 'oauth2'

//r.setAuthentication(authentication type, profile name);

var response = r.execute();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

}

catch(ex) {

var message = ex.getMessage();

}

However, nothing happens... I was monitoring my server, but no calls are received there either... Am I missing something all too obvious?

thanks!

Kind regards!

4 REPLIES 4

antin_s
ServiceNow Employee
ServiceNow Employee

You need to set the REST Type.



var r = new sn_ws.RESTMessageV2('Change record', 'POST'); // POST or GET based on what you need.



If that doesn't work, you can try something like below.



var method = "post";


var endpoint = 'https://www.your_endpoint_'


  var rm = new sn_ws.RESTMessageV2();


  rm.setHttpMethod(method);


  rm.setEndpoint(endpoint);


  var body = { some JSON stuff };


  rm.setRequestHeader("Content-type", "application/json");


  rm.setRequestBody(body);


  var response = rm.execute();


  var responseBody = new JSON().decode(response.getBody());



Hope this helps. Mark the answer as correct/helpful based on impact.



Thanks


Antin


tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi AA,



The link your have referred to


https://express.servicenow.com/support/videos/servicenow-express-outbound-rest/


has guidance on how you create outbound REST on the Express platform, this platform does not support scripting


https://express.servicenow.com/support/forums/topic/service-now-express-differences/



Your screenshots indicate you are implementing on Enterprise product so you should check out the Enterprise documentation.


This link, which includes a video, would be a good starting point.


Outbound REST web service



If the reply was informational, please like, mark as helpful or mark as correct!


johnram
ServiceNow Employee
ServiceNow Employee

The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here:
Outbound REST Web Service



Visit http://docs.servicenow.com for the latest product documentation


Neeraj Sharma10
Tera Guru

Hi AA,


Below links will help you in unsderstanding Outbouund rest and REST APIs



Outbound REST Web Service - ServiceNow Wiki


ServiceNow Integration (REST) - YouTube


Integration Best Practices — Outbound Web Services | John Andersen



You can write back to me if you still face problems. I recently gone through REST challenges and can you help you.



Thanks
Neeraj