Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

 

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
Tera Patron

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

 

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

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

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/atul_grover_lng [ 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