Default value to auto-populate cost center of Requested for user

Amy13
Tera Contributor

In a variable (reference to the cost center table), I'm looking to set the default value to the cost center of the user in the Requested for variable. How do I do this? This is what I have currently, but it's not working.

 

find_real_file.pngfind_real_file.png

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Should this happen onLoad or onChange?

For onLoad:
var gr = new GlideRecord('sys_user');gr.get(gs.getUserID());gr.getValue('cost_center');

For onChange:
Catalog Data Lookup Definition on any table, eliminating Catalog Client Scripting

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

I believe I want it to happen onLoad when the form loads. The requested for automatically populates to the signed in user. I want this variable to automatically populate with the signed in user's cost center.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

this should work fine and would store the logged in user's cost center

if the user is changed then you would require onChange client script to populate cost center as well.

Either use getReference with callback method or GlideAjax to populate the Cost center in the onChange client script of Requested For

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

It doesn't appear to be working for any of my items. Would you happen to know why?