<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Error Handling in ServiceNow for a OUTBOUND Rest message in Incident Management forum</title>
    <link>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2880031#M8248</link>
    <description>&lt;P&gt;I created a Scheduled Job. Running Periodically.&lt;/P&gt;&lt;P&gt;Please let me know if below script if fine or need modifications.&lt;/P&gt;&lt;P&gt;What else would be required apart from Scheduled Job?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Naveen87_0-1711605923967.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/343064iF1E5A023C12B70E6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Naveen87_0-1711605923967.png" alt="Naveen87_0-1711605923967.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Find incidents where correlation ID is not received and retry flag is set, //create a custom field called retry flag
var grIncident = new GlideRecord('incident');
grIncident.addQuery('correlation_id', '');
grIncident.addQuery('retry_flag', true); // Assuming you have a field to indicate retry is needed
grIncident.query();

while (grIncident.next()) {
   // Check if the last update time is more than 1 or 2 minutes ago
   var lastUpdated = new GlideDateTime(grIncident.sys_updated_on); // Assuming sys_updated_on field stores the last update time
   var currentTime = new GlideDateTime();
   var minutesSinceLastUpdate = GlideDateTime.subtract(currentTime, lastUpdated).getNumericValue() / (1000 * 60);
   if (minutesSinceLastUpdate &amp;gt;= 1 &amp;amp;&amp;amp; minutesSinceLastUpdate &amp;lt;= 2) {
	
       // Trigger the outbound REST message again
       var restMessage = new sn_ws.RESTMessageV2('global.EUW Ebonding', 'POST Incident');
       restMessage.setStringParameter('incident_number', grIncident.number); // Pass incident number or any other necessary parameters
       var response = restMessage.execute();
       // Check response and update incident accordingly
       if (response.getStatusCode() === 200) {
           // Update incident with correlation ID from response
           var responseBody = response.getBody(); // Assuming response body contains correlation ID
           grIncident.correlation_id = responseBody;
           grIncident.retry_flag = false; // Reset retry flag
           grIncident.update();
       } else {
           gs.error('Failed to trigger REST message for incident: ' + grIncident.number);
           // Handle error scenario - you can log error, update retry count, etc.
       }
   } else {
       // Update incident with appropriate status or log that retry time window has not passed
       gs.info('Retry time window has not passed for incident: ' + grIncident.number);
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Mar 2024 06:06:20 GMT</pubDate>
    <dc:creator>Naveen87</dc:creator>
    <dc:date>2024-03-28T06:06:20Z</dc:date>
    <item>
      <title>Error Handling in ServiceNow for a OUTBOUND Rest message</title>
      <link>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2875647#M8193</link>
      <description>&lt;P&gt;Hello Developers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are doing e-bonding via OUTBOUND Rest Message.&lt;/P&gt;&lt;P&gt;We are X company &amp;amp; OUTBOINDING to Y company.&lt;/P&gt;&lt;P&gt;There is a BR at place which will trigger the OUTBOUND with necessary Data from X to Y &amp;amp; a ticket will be created on Y company end.&lt;/P&gt;&lt;P&gt;Ticket number will be sent back as Acknowledgement &amp;amp; stored on Correlation ID on X company.&lt;/P&gt;&lt;P&gt;I want to set-up Error Handling, Just in case If ticket is not created on Y company, Network failure etc., could be reasons.&lt;/P&gt;&lt;P&gt;Where I could re-trigger it &amp;amp; new ticket is created on Y company.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure, If this is something which can be achieved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 05:22:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2875647#M8193</guid>
      <dc:creator>Naveen87</dc:creator>
      <dc:date>2024-03-25T05:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling in ServiceNow for a OUTBOUND Rest message</title>
      <link>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2875685#M8194</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/278531"&gt;@Naveen87&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in the same BR you can handle the retry mechanism.&lt;/P&gt;
&lt;P&gt;Something like if you don't get response then try for 2-3 times with a gap of 1min or so and if no response after all the try then create a email or ticket in instance X&lt;/P&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 06:20:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2875685#M8194</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2024-03-25T06:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling in ServiceNow for a OUTBOUND Rest message</title>
      <link>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2875778#M8196</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Can you please help me with line of codes to be written on BR.?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/ ) {


    try {
        var r = new sn_ws.RESTMessageV2('global.EUW Ebonding', 'POST Incident');
      
        r.setStringParameterNoEscape('u_customer_ticket_id', current.number);
        r.setStringParameterNoEscape('u_shr_priority', current.priority);
        r.setStringParameterNoEscape('u_shr_assignment_group', current.getDisplayValue('assignment_group'));
        r.setStringParameterNoEscape('u_pass_to_servicenow', 'Yes');
        r.setStringParameterNoEscape('u_ticket_type', 'Incident');
        r.setStringParameterNoEscape('u_transaction_type', '2');

        var response = r.execute();
        var responseBody = response.getBody();
        gs.info("responseBody " + responseBody);

        var jsonObj = JSON.parse(responseBody)
        var ticketid = jsonObj.result.u_partner_ticket_id;
        current.correlation_id = 'euwbond:' + ticketid;

        var correlation_id = current.correlation_id;
        if (!correlation_id) {
            // Field is empty, proceed with your desired action
            gs.addInfoMessage("Correlation ID is empty");
        } else if (correlation_id.includes("euwbond:INC")) {
            // Field contains "EUW bond", do nothing
            gs.addInfoMessage("Correlation ID contains 'euwbond'");
        } else {
            // Field contains something else, show error message
            gs.addErrorMessage("Correlation ID already set with 'euwbond'");
        }

        var httpStatus = response.getStatusCode();
    } catch (ex) {
        var message = ex.message;



    }

})(current, previous);&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 25 Mar 2024 07:45:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2875778#M8196</guid>
      <dc:creator>Naveen87</dc:creator>
      <dc:date>2024-03-25T07:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling in ServiceNow for a OUTBOUND Rest message</title>
      <link>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2878710#M8232</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you suggest the line of codes for this error handling.&lt;/P&gt;&lt;P&gt;I have shared my current BR configurations.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 08:40:36 GMT</pubDate>
      <guid>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2878710#M8232</guid>
      <dc:creator>Naveen87</dc:creator>
      <dc:date>2024-03-27T08:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling in ServiceNow for a OUTBOUND Rest message</title>
      <link>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2880031#M8248</link>
      <description>&lt;P&gt;I created a Scheduled Job. Running Periodically.&lt;/P&gt;&lt;P&gt;Please let me know if below script if fine or need modifications.&lt;/P&gt;&lt;P&gt;What else would be required apart from Scheduled Job?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Naveen87_0-1711605923967.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/343064iF1E5A023C12B70E6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Naveen87_0-1711605923967.png" alt="Naveen87_0-1711605923967.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Find incidents where correlation ID is not received and retry flag is set, //create a custom field called retry flag
var grIncident = new GlideRecord('incident');
grIncident.addQuery('correlation_id', '');
grIncident.addQuery('retry_flag', true); // Assuming you have a field to indicate retry is needed
grIncident.query();

while (grIncident.next()) {
   // Check if the last update time is more than 1 or 2 minutes ago
   var lastUpdated = new GlideDateTime(grIncident.sys_updated_on); // Assuming sys_updated_on field stores the last update time
   var currentTime = new GlideDateTime();
   var minutesSinceLastUpdate = GlideDateTime.subtract(currentTime, lastUpdated).getNumericValue() / (1000 * 60);
   if (minutesSinceLastUpdate &amp;gt;= 1 &amp;amp;&amp;amp; minutesSinceLastUpdate &amp;lt;= 2) {
	
       // Trigger the outbound REST message again
       var restMessage = new sn_ws.RESTMessageV2('global.EUW Ebonding', 'POST Incident');
       restMessage.setStringParameter('incident_number', grIncident.number); // Pass incident number or any other necessary parameters
       var response = restMessage.execute();
       // Check response and update incident accordingly
       if (response.getStatusCode() === 200) {
           // Update incident with correlation ID from response
           var responseBody = response.getBody(); // Assuming response body contains correlation ID
           grIncident.correlation_id = responseBody;
           grIncident.retry_flag = false; // Reset retry flag
           grIncident.update();
       } else {
           gs.error('Failed to trigger REST message for incident: ' + grIncident.number);
           // Handle error scenario - you can log error, update retry count, etc.
       }
   } else {
       // Update incident with appropriate status or log that retry time window has not passed
       gs.info('Retry time window has not passed for incident: ' + grIncident.number);
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 06:06:20 GMT</pubDate>
      <guid>https://www.servicenow.com/community/incident-management-forum/error-handling-in-servicenow-for-a-outbound-rest-message/m-p/2880031#M8248</guid>
      <dc:creator>Naveen87</dc:creator>
      <dc:date>2024-03-28T06:06:20Z</dc:date>
    </item>
  </channel>
</rss>

