Raise incident if connection fails

Vaibhav Kumar Y
Tera Expert

Hello,
I have done a data source integration with Rest integration hub where we are fetching users data from 3rd party system through Rest.
Now we have a requirement that while running this daily schedule import if the connection status code is not successful
then it should wait for 5 mins and then try again
And even after that if the connection is not getting successful then it should raise an incident.
Kindly let me know how can I achieve this.

7 REPLIES 7

Amit Gujarathi
Giga Sage
Giga Sage

HI @Vaibhav Kumar Y ,

I trust you are doing good.

To achieve this requirement, you can follow the steps below:

  1. Create a scheduled job in ServiceNow that runs the integration on a daily basis.

  2. In the integration script, add a loop that retries the connection if the status code is not successful. To achieve the wait time of 5 minutes, you can use the GlideDateTime method "addSeconds" to add 300 seconds to the current time. Here's an example of how to achieve this:

 

var retryCount = 0;
while (retryCount < 3) {
  var response = gs.sendRequest('http://example.com/api/users');
  if (response.getStatusCode() == 200) {
    // Process the data
    break;
  } else {
    retryCount++;
    gs.info('Connection failed, retrying in 5 minutes...');
    gs.sleep(300000); // Wait for 5 minutes before retrying
  }
}
if (retryCount == 3) {
  // Raise an incident
  var gr = new GlideRecord('incident');
  gr.short_description = 'Connection failed for data source integration';
  gr.insert();
}

 

 

  1. If the connection still fails after three retries, raise an incident by creating a new record in the Incident [incident] table. You can set the short description and any other necessary fields to describe the issue.

  2. You can also consider sending an email notification to the concerned team or person to inform them about the incident.

Please mark it helpful.

 

Regards,

Amit Gujrathi


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hello Amit,
Thank you for the suggestion.
Can we do it with integration hub?

Yes you can call the spoke itself from the script


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi