Business Rule- ChangesTo and Check for Empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 10:42 AM
Good afternoon community,
I am trying to implement a business rule that will check for a change on a boolean checkbox, where if it changes to true, a date/time field is populated with the current time.
(function executeRule(current, previous /*null when async*/) {
if (current.u_rca_approved.changesTo('true')) {
if (!current.u_rca_date_approved_on){
current.u_rca_date_approved_on.setValue(gs.now.DateTime());
}
}
})(current, previous);
This is supposed to check for a checkbox being checked, and if so, it checks if the date field is empty or not, and if empty, sets the current time. I am making a mistake someplace though, and I was hoping someone couple help me spot it?
Currently set as an AFTER rule.
When using the fields to trigger things, I could get it to work, but it would update the date every time the record was updated, since I was only able to check if RCA APPROVED = TRUE, which of course it is every time after it changes to true.
Thanks in advance for scripting/syntax help!
Jeff

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 10:56 AM
Hi Jeff,
You can change your business rule on before and use below script
Please check the
- (function executeRule(current, previous /*null when async*/) {
- if (current.u_rca_approved.changesTo('True')) {
- if (JSUtil.notNil(current.u_rca_date_approved_on)){
- current.u_rca_date_approved = gs.nowDateTime();
- }
- }
- })(current, previous);
OR
you can add u_rca_approved and u_rca_date_approved_on in business rule conditions.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 11:20 AM
Sachin,
I edited the script to include your changes-
(function executeRule(current, previous /*null when async*/) {
if (current.u_rca_approved.changesTo('True')) {
if (JSUtil.notNil(current.u_rca_date_approved_on)){
current.u_rca_date_approved_on = gs.nowDateTime();
}
}
})(current, previous);
It is still not working, and I am not getting any useful info from the business rule debugger. I can see the rule getting called, but no info-
I did not add any conditions as you note. Can I put in the conditions there, or should I, if they are listed explicitly in the script? I guess I am confused how to trigger using RCA APPROVED = TRUE, when it will be true every time after the first time. I only want to trigger the date set when it flips the first time.
is this what you think they should look like? I tried setting these and it made no change. It is not setting the date for sure, but I am not sure if it failing the conditions or what. I will add some log statements to track it down.
Jeff

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2018 11:25 AM
In business rule conditions, you can use below filter to check RCA changesTo true and also check for date.
Regards,
Sachin