Cost center of the logged in user need to be populated in the field

suuriya
Tera Contributor

Hi Community,

 

I have a requirement, in catalog form there is a field called "cost center for shipping" (single line text) in this field the cost center of the logged in user need to be populate in the field.

In user form there is field called cost center that value needs to be populate in the field.

user form:

suuriya_0-1700638294789.png

 

Thanks in advance

 

1 ACCEPTED SOLUTION

Can you try below

 

 

 

javascript:gs.getUser().getRecord().getDisplayValue('u_cost_center');

 

 

 


Please note that getValue will give you sys id of the cost center so if you want the display value, use getDisplayValue() instead.

also in above reponse of yours to get record you should not dot walk with .getUserID(), that is to return the sysID of logged in user specifically.

 

Hope that helps.

Consider indicating the response as helpful and marking it as correct if it meets your needs.

View solution in original post

4 REPLIES 4

Sonam_Tiwari
Kilo Sage

Hi @suuriya ,

Go through this thread and you should be able to write a similar script for autopopulating cost center from the required table.

https://www.servicenow.com/community/developer-forum/populate-field-value-based-on-another-field-usi...

Thanks,

Sonam

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

HI @Sonam_Tiwari ,

Thanks for the reply i checked but all are based on onchange script but i need to populate cost center of the  logged in user and not based on changing value of the field.

 

i tried something like this in default value  of the cost centre field/variable

 

javascript:gs.getUserID().u_cost_center();

 

but it is not working

Hi,

You can use it like:

gs.getUser().getRecord().getValue('u_cost_center'));  // u_cost_center is backend field name

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Can you try below

 

 

 

javascript:gs.getUser().getRecord().getDisplayValue('u_cost_center');

 

 

 


Please note that getValue will give you sys id of the cost center so if you want the display value, use getDisplayValue() instead.

also in above reponse of yours to get record you should not dot walk with .getUserID(), that is to return the sysID of logged in user specifically.

 

Hope that helps.

Consider indicating the response as helpful and marking it as correct if it meets your needs.