Not able to get the requester name auto populate (onload) in service catalog on service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 10:21 PM
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 10:34 PM
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 10:34 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 11:54 PM
By using this code I am not able to get the result in service portal but it is working fine in native UI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 12:09 AM - edited 11-15-2022 12:10 AM
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:
Regards,
Kamlesh