Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Display name based on condition

Chirag Pathak
Tera Contributor

Hi community I have catalog client script running on this record producer when the first variable is Are you logging this incident for someone else (yes/no)? it is no it should show the name of the logged in person but if yes it should its doing that in the backend but not on the portal.

Portal

ChiragPathak_2-1707722102984.png

Backend 

ChiragPathak_3-1707722152034.png

Catalog client script (Onchange client script)

ChiragPathak_4-1707722226531.png

 

 

 

8 REPLIES 8

Not applicable

 

Hi @Chirag Pathak  please try below one

 

if(isLoading || newValue=='Yes'){

g_form.clearValue('caller_id');

}else if(newValue=='No'){

g_form.setValue('caller_id',g_user.userID());

}

 

 

 

bihungb
Tera Contributor

Hi @Chirag Pathak ,

 

Please update your code with below code and it will work fine.

 

g_form.setValue('caller_id', g_user.userID);

 

To fetch the current logged_in user in client script you can use  g_user.userID.

You can refer the below link to have clear understanding of "The GlideUser (g_user) Class"

https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_script...

 

Kind Regards,

Bihung Basumatary

Dr Atul G- LNG
Tera Patron

Try cache.do once may be this is the issue.

 

or try to create script on another catalog item , just to test.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

SunilKumar_P
Giga Sage

Hi @Chirag Pathak, g_user.userID will get the sys_id of the current user in client script.

g_form.setValue('caller_id', g_user.userID);

 

Regards,
Sunil