- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2025 06:12 AM
Hi All,
How can we automatically calculate SLA duration based on the affected CI selected on the incident form?
Any suggestion, Script ??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2025 06:16 AM
Hi @vidishaagarwal5,
You can also refer to this discussion where a similar issue was addressed:
Solved: SLA Calculation - ServiceNow Community
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2025 06:32 AM - edited 10-21-2025 06:32 AM
As Suggested by @miftikhar20 check the Article : https://www.servicenow.com/community/developer-forum/sla-calculation/m-p/2675083
--------------
When it comes to Script use Business Rule :-
Script Example:
Table: incident
When: before insert / before update
(function executeRule(current, previous /*null when async*/) {
// Get the affected CI
var ci = current.cmdb_ci;
if (ci) {
var ciGR = new GlideRecord('cmdb_ci');
if (ciGR.get(ci)) {
var slaHours = ciGR.u_sla_duration_hours || 8; // Default 8 hours if blank
var gdt = new GlideDateTime();
gdt.addSeconds(slaHours * 3600);
current.u_due_date = gdt; // Update your custom SLA due date field
gs.info('SLA Duration set to ' + slaHours + ' hours for CI: ' + ciGR.name);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2025 06:16 AM
Hi @vidishaagarwal5,
You can also refer to this discussion where a similar issue was addressed:
Solved: SLA Calculation - ServiceNow Community
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2025 06:32 AM - edited 10-21-2025 06:32 AM
As Suggested by @miftikhar20 check the Article : https://www.servicenow.com/community/developer-forum/sla-calculation/m-p/2675083
--------------
When it comes to Script use Business Rule :-
Script Example:
Table: incident
When: before insert / before update
(function executeRule(current, previous /*null when async*/) {
// Get the affected CI
var ci = current.cmdb_ci;
if (ci) {
var ciGR = new GlideRecord('cmdb_ci');
if (ciGR.get(ci)) {
var slaHours = ciGR.u_sla_duration_hours || 8; // Default 8 hours if blank
var gdt = new GlideDateTime();
gdt.addSeconds(slaHours * 3600);
current.u_due_date = gdt; // Update your custom SLA due date field
gs.info('SLA Duration set to ' + slaHours + ' hours for CI: ' + ciGR.name);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2025 06:34 AM
Thanks @miftikhar20 and @Ravi Gaurav this helps