- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 02:14 AM
Hi Experts,
I want to populate the user's name in a field named 'Responsible Person' which we have to check from the 'Email Address' field on a record producer's multi row variable set.
In above image, Email Id is a string field. We have to check that email id from sys_user table and if it's there, we have to populate that user's name in the next field which is 'Responsible person'.
Let me know the approach and possible solution on it.
Thanks in advance,
Amol Pawar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 11:37 PM
Please adjust your function to:
getUserName: function() {
var email = this.getParameter('sysparm_email');
var user = new GlideRecord('sys_user');
user.addQuery('email', email);
user.query();
if (user.next()) {
return user.getDisplayValue('name');
}
return '';
},
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2025 03:19 AM
Glad to help.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 11:49 PM
Hi Amol,
I hope you are doing well!
Catelog Client script:
You need Create an ‘onChange’ Client Script on the Multi-Row Variable Set
Nav to Catalog Client Scripts > New.
Set the UI Type to All.
Apply it to your Multi-Row Variable Set.
Use the following script:
var email = newValue;
var ga = new GlideAjax('UserLookup'); // Call Script Include
ga.addParam('sysparm_name', 'getUserName');
ga.addParam('sysparm_email', email);//You can directly give it here and used this one as well g_form.getValue(email);.
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('responsible_person', response);
} else {
g_form.clearValue('responsible_person');
g_form.showFieldMsg('email_id', 'No matching user found.', 'error');
}
});
Server side script (script include):
getUserName: function() {
var email = this.getParameter('sysparm_email');
var userRec = new GlideRecord('sys_user');
userRec.addQuery('email', email);
userRec.query();
if (userRec.next()) {
return userRec.getValue('name'); // Fetch user name if its not working instead of this you can use this one(userRec.name.getDisplayvalue() )
}
return '';
}
I hope this one its working. let me know if you faced any issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 11:46 PM
why are you not putting Reference variable within that MRVS?
For your current requirement you can use GlideRecord with callback
OR
Enhance your script include as this, don't use initialize() method
var GetUserNameFromEmail = Class.create();
GetUserNameFromEmail.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUserName: function(email) {
var user = new GlideRecord('sys_user');
user.addQuery('email', email);
user.query();
if (user.next()) {
return user.getDisplayValue('name');
}
return '';
},
type: 'GetUserNameFromEmail'
});
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2025 02:45 AM
Thank you for marking my response as helpful.
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