- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 09:41 AM
I need the have the Cost Center Code show up in the list view of the Department table. I have created a custom field on the department table to keep this data. I need help with a BR to keep the two in sync if it changes on the Cost Center table. Two departments could use the same code.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 10:49 AM
Ok, then configure below script in business rule on cost center table to update cost center custom field on department table
Make sure to update correct custom center cost center field name in this script.
var dep = new GlideRecord('cmn_department');
dep.addQuery('u_cost_center',current.sys_id);
dep.query();
while(dep.next()){
dep.u_cost_center = current.sys_id;
dep.update();
}
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 10:49 AM
Ok, then configure below script in business rule on cost center table to update cost center custom field on department table
Make sure to update correct custom center cost center field name in this script.
var dep = new GlideRecord('cmn_department');
dep.addQuery('u_cost_center',current.sys_id);
dep.query();
while(dep.next()){
dep.u_cost_center = current.sys_id;
dep.update();
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 11:04 AM
Thanks so much -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 11:44 AM
I have one more question if you have a second. What would be involved in looping through the existing records in Department and updating them the the values in Cost Center? Would it be a lot of work?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 11:57 AM
You just have to configure fix script and then run this fix to update department records.
Use below as sample fix script
var cmn = new GlideRecord('cmn_cost_center');
cmn.addEncodedQuery('nameISNOTEMPTY');
cmn.query();
while(cmn.next()){
var dep = new GlideRecord('cmn_department');
dep.addQuery('u_cost_center',cmn.sys_id);
dep.query();
while(dep.next()){
dep.u_cost_center = cmn.sys_id;
dep.update();
}
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 09:09 PM
You are a real lifesaver!