I need the have the Cost Center Code show up in the list view of the Department table.

Jon M3
Tera Expert

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.

1 ACCEPTED SOLUTION

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

View solution in original post

9 REPLIES 9

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

Thanks so much - 

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?

You just have to configure fix script and then run this fix to update department records.

 

Fix Scripts

 

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

You are a real lifesaver!