- 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:28 AM - edited 01-24-2025 12:28 AM
@VinuvarshitSR - So what are you receiving in your log or alert statements?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 12:29 AM - edited 01-24-2025 12:30 AM
I am receiving the sys ids of the record but my script include is failing somewhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 12:48 AM
@VinuvarshitSR - You receiving sys_id of what and where you added logs? Don't just get panic or worried think what are you doing what is coming in what is going out. have some small break if you are stuck in between, it helps sometime.
Below is sample code I just ran on background script and see its output.
var listvalue = '019ad92ec7230010393d265c95c260dd,477a05d153013010b846ddeeff7b1225,d625dccec0a8016700a222a0f7900d06'; //this is sys_id of groups which will be coming from your client script
var teamEmails = [];
var grUser = GlideRecord('sys_user_group');
grUser.addQuery('sys_id','IN', listvalue);
grUser.query();
while(grUser.next()){
if(grUser.email!=''){
teamEmails.push(grUser.email.toString());
}
}
gs.print(teamEmails.toString());
/*Output:
Test@example.com,Test2@example.com,service.desk@yourcompany.com
*/
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 12:42 AM
Are you sure your script include is client callable and getting called successfully from client script?
Is that list field referring to sys_user_group table?
Assuming answer to above questions are yes then try this once
var ResponsibleTeamHandler = Class.create();
ResponsibleTeamHandler.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fetchGroupEmails: function() {
var teamIds = this.getParameter('sysparm_teams');
if (!teamIds) {
return '';
}
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: Assuming it's triggering on change of list field
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
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
}