- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 09:02 AM - edited 05-31-2025 08:12 PM
How to implement retry policy concept outside flow designer?
Ex - I want to retry API call 3 times. If still not successful, then create an incident.
PS - I know this capability is there in Flow designer but customer is having IH Starter package which has limited license count for IH transactions. Hence we are looking for solution outside the FLOW DESIGNER.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2025 11:04 PM
Hi @Suggy
ServiceNow offers the same concept OOTB with the ECC queue. And before you ask: No you don't need a MID server for that!
For you it means only a small change in your code and an additional configuration for retry policies. Please refer to the following article for more information: https://www.servicenow.com/community/itom-blog/ecc-failure-retry-async-rest-web-service-example/ba-p...
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2025 09:48 PM
Hi Suggy,
To implement a retry policy outside of Flow Designer in ServiceNow, you can use Server-Side Scripts (Script Includes, Business Rules, or Scheduled Jobs) to handle API retries.
Try this function inside your script :
executeWithRetry: function() {
var response = null;
var maxRetries= 5;
for (var i = 0; i < maxRetries; i++) {
try {
var restMessage = new sn_ws.RESTMessageV2(restMessageName, httpMethod);
restMessage.setRequestBody(parameters);
response = restMessage.execute();
// Check if the API call was successful (status code 2xx)
if (response.getStatusCode== 200) {
return response; // Return successful response
} else {
gs.info("Retry " + (i + 1) + ": API call failed with status code " + response.getStatusCode());
}
} catch (e) {
gs.error("Retry " + (i + 1) + ": Error during API call: " + e.message);
}
// Wait before retrying (e.g., 5 seconds)
if (i < maxRetries - 1) {
gs.sleep(5000); // Sleep for 5 seconds
}
}
return null; // Return null to indicate failure
}
tip: Adjust gs.sleep(5000) to change the delay between retries (like 10 seconds = gs.sleep(10000)), make sure your are not doing too much delays.
Please mark this as helpful and correct if this answers your question.
Thanks,
Yaswanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2025 02:53 AM
@YaswanthKurre Thanks for your inputs, but gs.sleep is not allowed in our production instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2025 11:04 PM
Hi @Suggy
ServiceNow offers the same concept OOTB with the ECC queue. And before you ask: No you don't need a MID server for that!
For you it means only a small change in your code and an additional configuration for retry policies. Please refer to the following article for more information: https://www.servicenow.com/community/itom-blog/ecc-failure-retry-async-rest-web-service-example/ba-p...
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2025 02:52 AM
Thanks Mark. Actually I thought it was deprecated when I couldnt find in my PDI. But its available in customer instances.