How to auto-populate the user Company and Cost center code in the "x" variable of catalog item.

Kruthika BM
Tera Contributor

Hi All,

 

I want to auto-populate the Company and Cost center code of the "requested for" user without writing client script/ UI policies. I want update on the variable level. I tried by providing the default value as "javascript:gs.getUser().getCompanyID();". But, I'm just getting the SysID of the Company. Tried by giving alternative value as well, like CompanyName.. but not working

Can anybody please help me to get the correct value of the Company and cost center code together. As I don't have idea, which backend value to be provided under "Default"

Example., Netherland - NL

 

Thanks in Advance!

 

Regards,

Kruthika 

 

5 REPLIES 5

Gabriel MF
ServiceNow Employee
ServiceNow Employee

Hi  Kruthika BM!

You can try to compose a GlideRecord to get the actual company record like this:

javascript:new GlideRecord('core_company').get(gs.getUser().getCompanyID())
 
And then dot walk to the field you need. For example:
javascript:new GlideRecord('core_company').get(gs.getUser().getCompanyID()).name

 

 Best regards,

Gabriel

Thank you, Gabriel, for the quick response. I try with this solution and if anything, else is needed, will get back to you.

 

Regards,

Kruthika

Deepak Shaerma
Kilo Sage

Hi @Kruthika BM 

javascript:var u = gs.getUser(); var c = new GlideRecord(‘core_company’); c.get(u.getCompanyID()); c.name;

Thank you, Deepak, for the quick response. I'll try to implement the provided solution and if anything, else is needed, will get back to you.

 

Regards,

Kruthika