Can a look up be added from Cost Center to replicate cost code and L2 leader in User table
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi Team,
We have a requirement to populate the users L2 leader and Cost Code in User table from Cost Center.
Example we have Department field in sys_user table however the L2 leader and Cost Code field has to be sync based on user code and the sync needs to be trigger from Cost Center as the Cost Center has Information of Department, L2 Leader and Cost Cost which is manually updated from our side.
Any assistance is highly appreciated.
Regards,
Jaison Swamy.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @JaisonS ,
To meet your requirement of syncing the L2 Leader and Cost Code fields in the sys_user table based on the related Cost Center record—that holds department, L2 leader, and cost code information—here is a recommended approach in ServiceNow:
The sys_user table has a Department field.
The Cost Center table stores Department, L2 Leader, and Cost Code.
When Cost Center data changes, you want to sync/update L2 Leader and Cost Code fields on the related users.
The sync needs to be triggered from Cost Center updates (single source of truth).
Approach:-
1. Define Fields
Ensure sys_user has custom fields for L2 Leader and Cost Code.
Confirm Cost Center table includes Department, L2 Leader, and Cost Code fields.
2. Use a Business Rule on Cost Center Table
Create a Business Rule on the Cost Center table that fires after update or after insert.
(function executeRule(current, previous /*null when async*/) {
// Query users with matching Department to Cost Center updated
var userGR = new GlideRecord('sys_user');
userGR.addQuery('department', current.department); // Assuming department reference field
userGR.query();
while (userGR.next()) {
// Update user fields from Cost Center
userGR.u_l2_leader = current.u_l2_leader; // Custom field for L2 Leader on user table
userGR.u_cost_code = current.u_cost_code; // Custom field for Cost Code on user table
// Update user record quietly, or with auditing as needed
userGR.update();
}
})(current, previous);
Replace u_l2_leader and u_cost_code with your actual custom field names on sys_user.
Adjust the field used to link department on both tables accordingly.
3. Performance and Data Integrity
If you have many users per Department, consider async Business Rule to prevent update lag.
Include proper error handling and logging.
Make sure that Department relationships are accurately maintained on the user and cost center.
4. Optional: Scheduled Job for Full Sync
If changes outside Cost Center updates occur (user department reassigned, bulk imports, etc.), consider a Scheduled Job that:
Periodically refreshes sys_user L2 Leader and Cost Code fields from Cost Center table values based on user’s department.
This ensures authoritative Cost Center data is automatically reflected in related User records, triggered by Cost Center changes, meeting your requirement efficiently.
Please refer to the below link:-
https://www.servicenow.com/community/developer-forum/i-am-trying-to-sync-a-field-with-a-field-in-ano...
https://www.servicenow.com/docs/bundle/xanadu-it-business-management/page/product/cost-management/ta...
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0721979
