- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 03:35 AM
Dear leaders ,
Can someone please help me with script for updating related records Description in Risk statement.
below 2 screen shots are GRC risk statement and related list have risks.
We have requirement to update all risk description if risk statement description is changed.
1>
2>
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 03:57 AM
you can use these steps
1) Always use after update BR on table "sn_risk_definition" to update records on another table
Condition: Description Changes
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sn_risk_risk");
gr.addQuery("statement", current.getUniqueValue());
gr.query();
while(gr.next()) {
gr.setValue('description', current.getValue('description'));
gr.update();
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 04:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 04:15 AM
Hi Ankur,
Thank you for values. I was not having GRC plugin activated on PDI so given close values and added comment asking user to update BR with correct field name and table name.
I have updated it now.
Can you please tell me difference between
gr.description = current.description;
AND
gr.setValue('description', current.getValue('description'));
Apart from this line rest you provided same solution as mine. Really interested to understand and learn the difference.
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 04:35 AM
Hi,
It is best practice and recommended to update related records/tables in an after update BR and not before update BR.
Also please check below link on the detailed explanation on setValue() method. Ideally wherever possible setValue() and getValue() should be used. But people tend to use current.field more often.
Avoiding Pass-By-Reference Using getValue() & setValue()
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 05:30 AM
Good to know but not finding where it says current.field is not good or bad practice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 05:38 AM
Hi,
Sharing some additional link; this is for getValue() but something similar for setValue()
Is GlideRecord getValue the King of the String
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader