Automatically create a work note and comment on RITM when a field in the Variables section changes

Khill
Tera Contributor

I've tried creating business rule client scripts to automatically create work note and comment message " Status changed to setup".  Nothing has worked. I tried  before insert business rule. I've tried after insert and update.

 

Example: 

 

Table : sc_req_item

When to Run : After - Insert

Condition: Item is laptop

 

Advanced:

 

If(current.variables.laptop == 'setup'){

 

current.work_note = 'Laptop has been moved to ' + current.variables.laptop;

}

 

Can anyone assist? 

}

2 ACCEPTED SOLUTIONS

Ethan Davies
Mega Sage
Mega Sage

In After or Asynchronous Business Rules you need to add current.update() to ensure your changes are committed. Also, the field is called 'work_notes' not 'work_note'.

 

 

if (current.variables.laptop == 'setup') {
        current.work_notes = 'Laptop has been moved to ' + current.variables.laptop;
        current.update();
    }
}

 

 If you use a before Business Rule, you do not need to specify current.update().

View solution in original post

Amit Gujarathi
Giga Sage
Giga Sage

HI @Khill ,
I trust you are doing great.
after business rules execute following the database action (insert, update, delete). Since you want to add a work note when a specific variable changes, you should use an after-update business rule. Here's an improved version of your script:

(function executeRule(current, previous /*null when async*/) {
    // Ensure this runs only when the 'laptop' variable changes to 'setup'
    if (current.variables.laptop == 'setup') {
        // Add a work note
        current.work_notes = 'Laptop has been moved to ' + current.variables.laptop;
        // Add a comment
        current.comments = 'Status changed to setup';
        // Update the record to commit the changes
        current.update();
    }
})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

2 REPLIES 2

Ethan Davies
Mega Sage
Mega Sage

In After or Asynchronous Business Rules you need to add current.update() to ensure your changes are committed. Also, the field is called 'work_notes' not 'work_note'.

 

 

if (current.variables.laptop == 'setup') {
        current.work_notes = 'Laptop has been moved to ' + current.variables.laptop;
        current.update();
    }
}

 

 If you use a before Business Rule, you do not need to specify current.update().

Amit Gujarathi
Giga Sage
Giga Sage

HI @Khill ,
I trust you are doing great.
after business rules execute following the database action (insert, update, delete). Since you want to add a work note when a specific variable changes, you should use an after-update business rule. Here's an improved version of your script:

(function executeRule(current, previous /*null when async*/) {
    // Ensure this runs only when the 'laptop' variable changes to 'setup'
    if (current.variables.laptop == 'setup') {
        // Add a work note
        current.work_notes = 'Laptop has been moved to ' + current.variables.laptop;
        // Add a comment
        current.comments = 'Status changed to setup';
        // Update the record to commit the changes
        current.update();
    }
})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi