- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 03:33 AM
I want to add one column which will show the date and time at which the status of request is change to Completed. I have created the column and created business rule to update the column with the date and time but somehow the script is not working. Please suggest any improvements
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 03:52 AM
you can use before update BR with correct condition
Script is this
current.setValue('u_completed', new GlideDateTime());
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 04:02 AM
Hi @Akshaykhare ,
You dont require to write script for this, just configure the business rule like below.
In when to run select state changes to completed.
And in action section select the date same as updated.
-------------------------------------------------------------------------
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
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 03:49 AM
Is this a Before BR?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 03:50 AM
Use this in a Before BR
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(current.u_request_state == '6'){
current.u_completed = new GlideDateTime();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 03:52 AM
you can use before update BR with correct condition
Script is this
current.setValue('u_completed', new GlideDateTime());
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 03:54 AM
a Business rule should run on the "After" update to capture changes to the status field after it's saved.
(function executeRule(current, previous /*null when async*/) {
// Check if the status has changed to "6"
if (current.status == '6' && previous.status != '6') {
// Set the custom date/time field with the current date and time
current.u_completed = new GlideDateTime();
}
})(current, previous);