Async business rule to fetch the date in which state is updated as fix in progress
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 06:36 AM
Hi,
I need to write a async business rule to fetch the date dynamically in which the problem state is changed to fix in progress. Can anyone give me the base idea?
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 06:59 AM
Hi @Nandhinisri ,
You can use below script in async BR to get the date and time.
// Fetch the history set for the Problem record
var history = new GlideRecord('sys_history_set');
history.addQuery('id', current.sys_id); // Match the history set with the Problem record
history.query();
if (history.next()) {
// Fetch the audit history lines for the history set
var auditH = new GlideRecord('sys_history_line');
auditH.addQuery('set', history.getValue('sys_id')); // Match with the history set sys_id
auditH.addEncodedQuery("field=state^new=Fix in Progress"); // Filter for state changes to "Fix in Progress"
auditH.query();
if (auditH.next()) {
// Print the update time when the state changed to "Fix in Progress"
gs.print('Update time is: ' + auditH.getValue('update_time'));
} else {
gs.print('No history found where the state changed to "Fix in Progress".');
}
} else {
gs.print('No history set found for the Problem record.');
}
I have checked it in background script, working fine.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------