- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2022 01:17 AM
i have written 1 client script where as soon as the person loggs in, his name and mail would be populated. when i "try it" in the catalog, it is getting populated when i use the service portal, the name is getting populated but in the email field, at the top an error message is coming in portal saying "there is a javascript error in your browser console".
function onLoad() {
//Type appropriate comment here, and begin script below
var a=g_user.userID;
g_form.setValue('name',a);
var b=g_form.getReference('name');//user table
g_form.setValue('email',b.email);
}
can any1 tell me what i am doing wrong
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2022 01:47 AM
Hi RC,
Whilst Murthy is correct to point you to best practice and use GlideAjax to fetch server data from the client, there is a way to do this very easily.
Rather than call an onLoad script, set the default values for each field by configuring the variable.
For the email field, set the default value to: javascript: gs.getUser().getEmail();
For the name field, set the default value to: javascript: gs.getUserID()
These will work on both the catalog native view and the Service Portal.
Please mark correct and/or helpful.
Thanks,
Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2022 01:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2022 03:22 AM
Hi RC,
If you want get manager
Try like this in default value:
javascript:gs.getUser().getRecord().getValue("manager"); //map correct field_name
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2022 01:47 AM
Hi RC,
Whilst Murthy is correct to point you to best practice and use GlideAjax to fetch server data from the client, there is a way to do this very easily.
Rather than call an onLoad script, set the default values for each field by configuring the variable.
For the email field, set the default value to: javascript: gs.getUser().getEmail();
For the name field, set the default value to: javascript: gs.getUserID()
These will work on both the catalog native view and the Service Portal.
Please mark correct and/or helpful.
Thanks,
Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2022 02:58 AM
this was correct. can u plz explain the meaning of the line gs.getUser().getEmail(); so we are going to the user table by gs.getuser() and through getEmail() we are fetching the value? . what is this getEmail basically like for example if i wanted to get the manager name also from the user table so i should write gs.getUser().getfieldname ??