- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 11:53 AM
Hi, I am currently working on a catalog item where the user selects a group, and I wanted to populate the email group on another field.
The first field is called name which is a reference to the sys_user_group table and the field email is where I want the email of the group selected. This is what I got so far:
Script Include:
var getGroupEmail = Class.create();
getGroupEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getData: function() {
var recordGroup = this.getParameter('sysparm_group');
var group = new GlideRecord('sys_user_group');
group.get(recordGroup);
var result = this.newItem('result');
result.setAttribute('email', group.email);
}
// type: 'getGroupEmail'
});
And this is the catalog client script that I have:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == '') {
return;
}
var group = g_form.getDisplayValue('name');
alert(group);
var ga = new GlideAjax('getGroupEmail');
ga.addParam('sysparm_name', 'getData');
ga.addParam('sysparm_group', group);
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var result = serverResponse.responseXML.getElementsByTagName('result');
g_form.setValue('email', result);
}
}
In the email field, I am getting: [object HTML.Collection]
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 12:13 PM - edited 11-13-2023 12:14 PM
I figured out that, no need to go with the script included. I just created this other catalog client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var result = g_form.getDisplayValue('name');
// alert(result);
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name', result);
gr.query(myCallbackFunction);
function myCallbackFunction(gr) {
while (gr.next()) {
// alert(gr.email);
g_form.setValue('email', gr.email);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 12:02 PM
Try returning the email field, forced to a string:
var getGroupEmail = Class.create();
getGroupEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getData: function() {
var answer = '';
var recordGroup = this.getParameter('sysparm_group');
var group = new GlideRecord('sys_user_group');
if (group.get(recordGroup)){
answer = group.email.toString();
}
return answer;
}
// type: 'getGroupEmail'
});
Then use 'answer' in the client script callback function instead of result.
Note that in the Utah version and later you can do this without the scripts via the auto populate feature
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 12:11 PM
Hi Brad, thanks for your reply. I tried but it didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 12:13 PM - edited 11-13-2023 12:14 PM
I figured out that, no need to go with the script included. I just created this other catalog client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var result = g_form.getDisplayValue('name');
// alert(result);
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name', result);
gr.query(myCallbackFunction);
function myCallbackFunction(gr) {
while (gr.next()) {
// alert(gr.email);
g_form.setValue('email', gr.email);
}
}
}