Checking or unchecking Active check box, should update the active or inactive date fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 11:55 AM
Hi,
I have created Active field as true/false to check/uncheck and created active date and inactive date fields as date/time. Now when the active box is true, active date should be updated with date when the active box was made true. When 'active' is false, inactivate date should be updated with the date when the active box was made false. How to achieve this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 12:01 PM
Hello,
You can create a before business rule with filter condition (Active | Changes) with the script as
if(current.u_active == 'true')
{
current.u_active_date = gs.nowDateTime();
}
else
{
current.u_inactive_date = gs.nowDateTime();
}
Modify the field column name accordingly.
-Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 12:10 PM
This form is under a scoped application. Still this code works? do i have to do script includes otherwise?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 12:13 PM
This will not work for Scoped Applications. Updated code below
if(current.u_active == 'true')
{
current.u_active_date = new GlideDateTime().getDisplayValue()
}
else
{
current.u_inactive_date = new GlideDateTime().getDisplayValue()
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 01:05 PM
This code is not working. I do not know if this is because of the getDisplayvalue or any other thing is breaking. I have set the When to run as "before" and checked insert or update and filter condition to "Active = Changes" and in the code,
(function executeRule(current, previous /*null when async*/) {
// Add your code here
//Type appropriate comment here, and begin script below
if(current.active == 'true'){
current.active_date = new GlideDateTime().getDisplayValue();
}
else{
current.inactive_date = new GlideDateTime().getDisplayValue();
}
})(current, previous);
And the dates will change accordingly whenever the user opens an existing record and modify the active check box and also when new record inserted.