Not able to get the requester name auto populate (onload) in service catalog on service portal

Community Alums
Not applicable

I have written a code in catalog client script under maintain item and the code is running on the native UI but not in the service portal.

My code is:-

 

 

function onLoad() {
//Type appropriate comment here, and begin script below
// g_form.setValue('requester_name', g_user.getFullName());
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', g_user.userID);
gr.query(call);

function call(gr) {
g_form.setValue('requester_name', g_user.getFullName());
while (gr.next()) {
g_form.setValue('business_phone', gr.phone);
g_form.setValue('email_id', gr.email);
}
}
}

6 REPLIES 6

Voona Rohila
Kilo Patron
Kilo Patron

Hi Utsav

 

It's not recomended to use GlideRecord in client script, You can use getRefernce or GlideAjax to get the userr details

 

refer below links

https://www.servicenow.com/community/developer-articles/get-user-details-based-on-the-logged-in-user... 

 

http://www.servicenowguru.com/scripting/user-object-cheat-sheet/

 

https://servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Just wondering why are you calling a function when you already have glided the record?

 

 function onLoad() {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', g_user.userID);
gr.query();
if (gr.next()) {
g_form.setValue('requester_name', gr.name);
g_form.setValue('business_phone', gr.phone);
g_form.setValue('email_id', gr.email);
}
}

 

Please mark my answer as correct based on Impact. 

Community Alums
Not applicable

By using this code I am not able to get the result in service portal but it is working fine in native UI.

Hi @Community Alums  ,

 

Could you please confirm if your UI type of your client script is selected as All and not Desktop, as shown below. Many times we forget to change it to All and hence it works in the native UI and not on portal:

 

kamleshkjmar_0-1668499736789.png

 

 

Regards,

Kamlesh