
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2021 08:19 AM
Hi everyone,
I have a table 2 called (sn_compliance_control) where I have a custom string field(u_control_id). I would like this field to be updated from another table 1 (sn_compliance_policy_statement)'s field called "Reference"(reference).
N.B. the field reference is a string field found within the table
I wrote after BR in table 1 with
- Condition set to (Reference is not empty),
- When set to async, and
- Advanced checked (insert, update, query)
Here is my script:
(function executeRule(current, previous /*null when async*/) {
var referenceValue = new GlideRecord('sn_compliance_control');
referenceValue.addQuery('u_control_id', current.reference);
referenceValue.query();
while (referenceValue.next()){
referenceValue.setValue('u_control_id', current.reference);
referenceValue.update();
}
})(current, previous);
My goal is to update all control id in my table 2 with table one value. I need a second eye to my BR/code since it's not doing the way it supposed to do?
Thanks,
Mokemal!
Solved! Go to Solution.
- 2,999 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2021 11:17 AM
Thanks
As parent record will not change after it is inserted. We created a scheduled job to update the Control ID field of the child tables.
If you need you can create a before BR on sn_compliance_control
var referenceValue = new GlideRecord('sn_compliance_policy_statement');
if(referenceValue.get(curent.content)
{
current.u_control_id=referenceValue.reference
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2021 10:02 AM
Hi Mark,
It's working when you open the Control objective record and made an update to the field(Reference). It then populate the control id in the control table.
But in my case, the field "Reference" is not going to be updated once it's set in the control objective table.
That's why I set the BR, When = async
but the code isn't running?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2021 10:06 AM
So did you add any debugging? Is the Business Rule itself for example triggered? Maybe you made a mistake somewhere.
I also just tested with the condition you mentioned, reference is not empty + async. Still works here.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2021 10:10 AM
Attached the Business Rule I setup and which is working on my PDI.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2021 09:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2021 08:35 AM
Make sure BR is on sn_compliance_policy_statement table and try below code
var referenceValue = new GlideRecord('sn_compliance_control');
referenceValue.addQuery('u_control_id', current.reference);
referenceValue.setValue('u_control_id', current.reference);
referenceValue.updateMultiple();