
- 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,993 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 08:27 AM
Hi there,
Have a close look at:
referenceValue.addQuery('u_control_id', current.reference);
And:
referenceValue.setValue('u_control_id', current.reference);
You are quering on u_control_id = current.reference. And then setting the same? That won't work right?
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 08:28 AM
Is the Business Rule running against table "sn_compliance_policy_statement"?
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 08:35 AM
Table "sn_compliance_control" has a reference to table "sn_compliance_policy_statement". The reference field is "content". So you can query on this field to get the record(s) you are after to update.
(function executeRule(current, previous /*null when async*/) {
var referenceValue = new GlideRecord('sn_compliance_control');
referenceValue.addQuery('content', current.getUniqueValue());
referenceValue.query();
while(referenceValue.next()){
referenceValue.setValue('u_control_id', current.reference);
referenceValue.update();
}
})(current, previous);
You do also mention that the field to update is a string field, while the field from is a reference. So you might want to use the displayValue?
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 08:38 AM
Ah I see just checked on my PDI, the field with name "reference" is actually a String haha. So that won't be an issue.
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