- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2024 08:36 AM
Hi everyone,
I need to trigger a business rule in a parent record (e.g., Incident) when a field in a related child record (e.g., Work Note) is updated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2024 12:05 AM - edited ‎10-03-2024 12:07 AM
Hi @thullurishalini ,
I accomplished this by creating a business rule on the Work Note (Journal) table (sys_journal_field) that updates a field in the parent Incident when a work note is modified. This in turn triggers a business rule on the parent Incident.
You can follow the below steps and Code for business rule to achieve this:
- Create a Business Rule on the Work Note (Journal) table (sys_journal_field).
- In the Business Rule:
a. When: After
b. Condition: You can specify your own condition, such as when a specific field is updated.
c. Script:
(function executeRule(current, previous /*null when async*/) {
if (current.element_id == 'incident') { // Check if the work note is related to an incident
var incidentGR = new GlideRecord('incident'); // Get the parent incident record
if (incidentGR.get(current.element)) {
// Write the script what you want to perform
}
}
})(current, previous);
===================================***************=========================================
"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
Thanks & Regards,
Aditya
=====================================***********==========================================
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2024 11:39 AM
Hi @thullurishalini.
Create a After BR on table (sys_journal_field) so whenever the worknote updated the BR triggers
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2024 10:16 PM
You can use the script in the BR at the advance tab as follows
if (current.your_field_name.changes()) {
var parentRecord = new GlideRecord('incident');
if (parentRecord.get(current.parent)) {
parentRecord.state = '3';
parentRecord.update();
}
}
This may help you to trigger the BR
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2024 12:25 AM
Please refer to this link. It may helps to you
Refer: https://www.servicenow.com/community/developer-forum/need-business-rule-to-update-parent-state/m-p/1...
Please mark this response as correct or helpful if it assisted you with your question.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2024 11:00 PM
Create a Business Rule on the Work Note (Journal) table (sys_journal_field). Follow these steps:
- When: Set the condition to "After" the record is saved.
- Condition: Define your specific condition, such as triggering when a particular field is updated.
- Script:
(function executeRule(current, previous /*null when async*/) {
// Check if the work note is associated with an incident
if (current.element_id == 'incident') {
var incidentGR = new GlideRecord('incident'); // Query the parent incident record
if (incidentGR.get(current.element)) {
// Add the logic you want to execute here
}
}
})(current, previous);