Business rule invocation for every new incident creation is not working

SenthilkumaK
Tera Contributor

Hello Team,

 

I need to call an external API endpoint for every new incidents / updates to the existing incident in Service Now. So i have created a Business rule with the below contents. But i am not sure where to check whether the business rule is invoked for every new incident creation / updation.

 

Could someone guide where to check or any issue with this script

 

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    gs.log("[REST API CALL] init");
    var requestBody;
    var responseBody;
    var status;
    var sm;

   try{

   rm = new sn_ws.RESTMessageV2('Invoke Quant Endpoint', 'post');

 //  rm.setHttMethod('POST');
 //  rm.setEndpoint('<my endpoint>');

//   rm.setRequestHeader("Content-Type", "application/json"); 
//   rm.setStringParameter("source", "SNOW");
//   rm.setHttpTimeout(10000);
   requestBody = {
    "short_description": current.short_description,
    "priority": current.impact,
    "state": current.state
   };
   rm.short_description = current.short_description;
   rm.requestBody = JSON.stringify(requestBody);

   var response = rm.execute();
   responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
   status = response.getStatusCode();

   gs.log("[REST API CALL] status code: "+response.getStatusCode());

   }catch(ex){
   gs.log("[REST API CALL] exception"+ex);
   responseBody = ex.getMessage();
   status = '500';
   } finally {
    requestBody = rm ? rm.getRequestBody():null;
   }      
   gs.info("Request Body: " + requestBody);
   gs.info("Response: " + responseBody);
   gs.info("HTTP Status: " + status);
  }
) (current, previous);
1 ACCEPTED SOLUTION

Swapna Abburi
Mega Sage
Mega Sage

Hi @SenthilkumaK 

As you have debug logs configured in your script, you can check in the system logs. For checking logs easily, you can add source to the log message and filter logs using source column.

Sample log message below. Here apiTesting is the source that you can use to filter the logs.

gs.log("msg you want to display in logs", "apiTesting");

 

Also, type "Outbound Http Requests" in the Left navigator, which shows the outbound api requests and their status information.

View solution in original post

3 REPLIES 3

Swapna Abburi
Mega Sage
Mega Sage

Hi @SenthilkumaK 

As you have debug logs configured in your script, you can check in the system logs. For checking logs easily, you can add source to the log message and filter logs using source column.

Sample log message below. Here apiTesting is the source that you can use to filter the logs.

gs.log("msg you want to display in logs", "apiTesting");

 

Also, type "Outbound Http Requests" in the Left navigator, which shows the outbound api requests and their status information.

Thank you @Swapna Abburi 

SenthilkumaK
Tera Contributor

Thank you @Swapna Abburi