- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 06:33 AM
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?
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 07:18 PM - edited 12-05-2023 08:25 PM
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().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 08:22 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 07:18 PM - edited 12-05-2023 08:25 PM
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().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 08:22 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Amit
When sending messages from the notes section within ServiceNow, it is important to be aware that certain key details are not automatically included in the message. Specifically, the contract reference, Publisher, and name information are omitted by default.
Details to be Automatically Included
• Contract reference
• SCTask number
• Publisher
• Name information..
so they want to add these details automaticaly without manual intervention, i tried business rule but the details are not fetching , can you help me?
