Business duration left on Incident form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi all,
I have created a new field named as business time left and Wrote a business rule on incident table to query the related task sla record and copy the same value and gets pasted there. now the field is not populated. I am pasting my script below.
My requirement is when the business time left in task sla changes, The field on the incident form should also reflect same.
It is an ASYNC business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
you should have after update BR on task_sla with condition as Business time left Changes
(function executeRule(current, previous /*null when async*/ ) {
// Ensure we are only targeting incidents
if (current.task.sys_class_name == 'incident') {
var incidentGR = new GlideRecord('incident');
if (incidentGR.get(current.task)) {
// Copy the business time left value from task_sla to the incident
incidentGR.u_business_time_left.setDateNumericValue(current.business_time_left.dateNumericValue());
incidentGR.update();
}
}
})(current, previous);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Hi @Abishek1998
What type of Field business time left is?
In this line parse the value properly , it will be set .
current.u_business_time_left = slaGR.getValue('business_time_left');
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
40m ago
Hey @Abishek1998
The main issue is that your Business Rule is running on the Incident table, while the business_time_left field is updated on the related task_sla record. Changes to a Task SLA record do not trigger a Business Rule on the Incident table, so the Incident field will not automatically stay in sync.
For this requirement, I would recommend creating an After Update Business Rule on the Task SLA [task_sla] table and updating the related Incident whenever business_time_left changes.
Business Rule Configuration:
Table: Task SLA [task_sla]
When: After Update
Condition: current.business_time_left.changes()
Script :
(function executeRule(current, previous) {
// Ensure the Task SLA is associated with an Incident
var incGR = new GlideRecord('incident');
if (incGR.get(current.task)) {
incGR.setValue(
'u_business_time_left',
current.getValue('business_time_left')
);
// Prevent unnecessary workflow processing if desired
incGR.setWorkflow(false);
incGR.update();
}
})(current, previous);
A few additional points:
- Avoid using current.update() inside a Business Rule on the same record unless absolutely necessary, as it can lead to recursion and performance issues.
- Verify that u_business_time_left is the correct field type to store the SLA value.
- If multiple SLAs exist on the Incident, you may need additional filtering to identify the correct SLA record (for example, Resolution SLA only).
This approach ensures that whenever the SLA engine updates business_time_left, the Incident field is updated as well.
*************************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb