Checking or unchecking Active check box, should update the active or inactive date fields

Ronak3
Tera Contributor

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?

6 REPLIES 6

Try the updated code below and make sure column names are correct.

 

(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);

Abhinay Erra
Giga Sage

Create a before business rule 

when: before insert and update

conditions: Active changes

Script:

 

if(current.active){

current.<field_name of active date> =gs.nowDateTime();

//current.<field_name of inactive date>='' ;//take out the comments if you need to clear the inactive date

}

else{

current.<field_name of inactive date>=gs.nowDateTime();

//current.<field_name of active date>='' ;//take out the comments if you need to clear the active date

}