Retry and Error Mechanism for Rest outbound integration

Resham Noor
Tera Contributor

Hi Folks,

I am currently implementing a REST Outbound integrations to send the CI information to Workspace Third party tool.

It is a uni-directional integration and no other major stuff.

FYI: using schedule job and script include so no flows involved here for error handling.

I would appreciate if someone could share the retry mechanism and error handling issues to be included in the script

 

 

try {
     r.setRequestBody();
    var response = r.execute();
    if (response) {
        var responseBody = response.getBody();
        var httpStatus = response.getStatusCode();
        gs.log('Asset ID: ' + gr.getValue('sys_id') + ', Response: ' + responseBody + httpStatus);
    } else {
        //ERROR Handling mechanism
        gs.log('Error: The response from the REST call was null or undefined.');
    }
} catch (e) {
    gs.log('REST call failed with error: ' + e.toString());
}

@Community Alums @AndersBGS @Ankur Bawiskar  @Amit Gujarathi @Maik Skoddow 

 

 

2 REPLIES 2

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Resham Noor 

 

1. Do you have a set of common error that you get ? If yes store them in servicenow to associate a retry/error mechanism using scheduled jobs.

 

2. You can create a workflow with all common errors which triggers the retry or fix mechanism. This will again run condition or scheduled bases.

 

3. If the errors received as minimal , lets say 2 or 3 you can simply feed them in rest call itself to retry based on getStatusCode();

 

I hope this helps...

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Ankur Bawiskar
Tera Patron
Tera Patron

@Resham Noor 

you need to have custom logic for this

you can have max 3 retry count and loop it and wait for 2-3mins for every loop

example: start with count as 1 and hit the API, check the response if it fails wait for 2-3mins and then again run the loop, increment the count as 2 and do same

stop the loop when count reaches 3

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader