- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2025 11:58 PM
I have 2fileds one is list for responsible group which is a list type and the other one is responsible dl i would like to auto populate dl if the user select the groups from the list using glide ajax i have written script but it's not working
Script include
Script include
var ResponsibleTeamHandler = Class.create();
ResponsibleTeamHandler.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fetchGroupEmails: function() {
var teamIds = this.getParameter('sysparm_teams');
if (!teamIds) {
return '';
}
var teamEmails = [];
var teamIdsArray = teamIds.split(',');
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', 'IN', teamIdsArray);
gr.query();
while (gr.next()) {
if (gr.email) {
teamEmails.push(gr.email.toString());
}
}
return teamEmails.join(', ');
},
type: 'ResponsibleTeamHandler'
});
Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('ResponsibleTeamHandler');
ga.addParam('sysparm_name', 'fetchGroupEmails');
ga.addParam('sysparm_teams', newValue);
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_responsible_team_dls', answer);
});
// Add any additional code required here
}
Kindly help in resolving the issue
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2025 09:12 PM
This worked and Thanks for the support I changed a few. @Viraj Hudlikar @NagaChandaE and @Ankur Bawiskar
here is the code
Script include
var ResponsibleTeamHandler = Class.create();
ResponsibleTeamHandler.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fetchGroupEmails: function() {
var teamIds = this.getParameter('sysparm_teams');
if (!teamIds) {
return '';
}
var teamEmails = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', 'IN', teamIds);
gr.query();
while (gr.next()) {
if (gr.email) {
teamEmails.push(gr.email.toString());
}
}
return teamEmails.join(', ');
},
type: 'ResponsibleTeamHandler'
});
Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('ResponsibleTeamHandler');
ga.addParam('sysparm_name', 'fetchGroupEmails');
ga.addParam('sysparm_teams', g_form.getValue('u_responsible_teams'));
ga.getXMLAnswer(function(answer) {
g_form.setValue('u_responsible_team_dls', answer); // Set the response in the desired field
});
// Add any additional code required here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2025 12:07 AM - edited ‎01-24-2025 12:12 AM
While using getXMLAnswer you not need to write response you directly use the answer attribute below example.
var ga = new GlideAjax('QuickQuery'); ga.addParam('sysparm_name', 'getField'); ga.addParam('sysparm_table', 'x_hotel_guest'); ga.addParam('sysparm_sys_id', newValue); ga.addParam('sysparm_field', 'vip'); ga.getXMLAnswer(function(answer) { if (answer == 'true') { g_form.showFieldMsg('guest', 'Guest is a VIP!'); } });
below i corrected your code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('ResponsibleTeamHandler');
ga.addParam('sysparm_name', 'fetchGroupEmails');
ga.addParam('sysparm_teams', newValue);
ga.getXMLAnswer(function(answer) {
g_form.setValue('u_responsible_team_dls', answer);
});
// Add any additional code required here
}
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
@NagaChandaE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2025 12:13 AM
Thanks a lot for your solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2025 12:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2025 12:26 AM
I have tried it but not working. it's fetching the sys id but not fetching the mail ids.