- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2022 07:52 AM
Hi Team,
I have two tables, one is 'sn_customerservice_setup' another one is 'sn_customerservice_codes'.
In setup table i have a filed called u_codes which refers to sn_customerservice_codes table.
and in codes table i have a field called u_setup which refers to sn_customerservice_setup table.
My requirement is when setup table is updated (u_codes field is filled and saved/updated), i need to autopopulate the u_setup field in sn_customerservice_codes table.
i wrote a after insert Business rule on sn_customerservice_setup table with no luck.
Please correct it.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sn_customerservice_codes');
gr.addQuery('sys_id', current.u_codes);
gr.query();
if(gr.next()){
gr.u_setup == current.sys_id;
gr.update();
}
})(current, previous);
Thanks in advance,
Hari Kishan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2022 09:53 AM
Please find updated code below:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sn_customerservice_codes');
gr.addQuery('sys_id', current.u_codes);
gr.query();
if(gr.next()){
gr.u_setup = current.getUniqueValue(); //current.sys_id id this does not works
gr.update();
}
})(current, previous);
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2022 09:53 AM
Please find updated code below:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sn_customerservice_codes');
gr.addQuery('sys_id', current.u_codes);
gr.query();
if(gr.next()){
gr.u_setup = current.getUniqueValue(); //current.sys_id id this does not works
gr.update();
}
})(current, previous);
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2022 10:14 AM
Your Business rule should be an after insert/update business rule with condition, when setup field changes with below script
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sn_customerservice_codes');
gr.addQuery('sys_id', current.getValue('u_codes'));
gr.query();
if(gr.next()){
gr.u_setup = current.getValue('sys_id');
gr.update();
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.