- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 02:01 AM
I have a variable of type Lookup Select box which is refering to sys_user table. I want to autopopulate the selected user email in another text box field. How can i achieve this.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 02:13 AM - edited 04-19-2023 02:24 AM
Hi @Sanjay21 ,
You can write a onChange Catalog client script and use Client Side GlideRecord to get the user email, or you can use GlideAjax to get the user details and display in the other field.
But, The best practice is to use the GlideAjax and call a ClientCallable Script Include to get the user details.
You can use the following scripts, but make sure to change the field names in onChange client script to the one you are using.
Client Callable Script Include:
var CatalogUserData = Class.create();
CatalogUserData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserEmail: function(){
var user = this.getParameter('sysparm_user');
var usrGr = new GlideRecord('sys_user');
if(usrGr.get('sys_id', user)){
return usrGr.getValue('email');
}else{
return '';
}
},
type: 'CatalogUserData'
});
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading && newValue) {
var kbGa = new GlideAjax('CatalogUserData');
kbGa.addParam('sysparm_name', 'getUserEmail');
kbGa.addParam('sysparm_user', newValue);
kbGa.getXMLAnswer(populateEmail);
}
function populateEmail(answer) {
if (answer) {
g_form.setValue('user_email', answer);
} else {
g_form.setValue('user_email', '');
}
}
}
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 11:17 PM
Hi Mehta,
Thanks for the answer but this works only for reference fields not for lookup select box.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 11:34 PM
Please use reference type and not look up select box
No scripting required. you can use Catalog Lookup definition for this
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader