populate cost center code in default logged in user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 10:14 AM
Hello,
For logged in user i need to show the cost center code as default,
I have tried the below code in default value but it is not working.
javascript: var gr= new GlideRecord('sys_user');gr.get(gs.getUserID());gr.getValue('cost_center');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 10:20 AM
Hello @Anubhav Srivas1 ,
To show the cost center code as the default value for a field in ServiceNow, you can use the following code in the default value script:
javascript: (function() {
var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
return gr.getValue('cost_center');
})();
Make sure to set the default value script of the field to the above code. This script retrieves the current logged-in user's sys_user record and gets the value of the cost_center field. The returned value will be used as the default value for the field.
Please mark this response as correct and/or helpful if it assisted you
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 05:52 PM
Hi,
i'm getting the cost center sys id when i try this. I need the cost center code.
cmn_cost_center.do?sys_id=ea57131fdbc6c30002ea788bbf961911&sysparm_view=
the sys id shows above is displaying and not the actual value of the cost center.