Add groups to variable field through automation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 03:44 AM
Hi Everyone.
I have a requirement where i need to add groups of one variable to other variable in a catalog item.
We have one variable called AD group, and other variable Company groups. This company groups is a list collector variable it has reference to a company group table. In every record company group table there is one variable called Org groups. When we select any company group record , the data in that org groups field of that particular company group should be appended to AD group variable. How can i achieve this?
Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2025 04:44 AM
Hi
Function name has to be what you provide in sysparm_name, in your case function name is different in script include GetAADValues.
Also try to add logs to check where your code is creating issues
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2025 03:01 AM
try this
var GetOrgValues = Class.create();
GetOrgValues.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOrgValues: function() {
var ids = this.getParameter('sysparm_ids');
if (!ids) return '[]';
var idArray = ids.split(',');
var result = [];
var gr = new GlideRecord('u_company_group');
gr.addQuery('sys_id', 'IN', idArray);
gr.query();
while (gr.next()) {
var aad = gr.getValue('u_org_group');
if (aad) {
result.push(aad);
}
}
return JSON.stringify(result);
}
});
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var selectedIDs = g_form.getValue('u_company_groups');
if (!selectedIDs) return;
var currentADGroup = g_form.getValue('vo_ad_groups');
var ga = new GlideAjax('GetOrgValues');
ga.addParam('sysparm_name', 'getOrgValues');
ga.addParam('sysparm_ids', selectedIDs);
ga.getXMLAnswer(function(response) {
if (!response) return;
var aadvalues = JSON.parse(response);
var newADGroupValue = currentADGroup;
if (aadvalues.length > 0) {
// Remove duplicates if needed
var existing = currentADGroup ? currentADGroup.split(',') : [];
var combined = existing.concat(aadvalues);
// Remove empty strings and duplicates
var unique = Array.from(new Set(combined.filter(Boolean)));
newADGroupValue = unique.join(',');
}
g_form.setValue('vo_ad_groups', newADGroupValue);
});
}
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
07-10-2025 03:41 AM
Hi @Ankur Bawiskar , i have tried this and i am getting error like "there is java script error in your browser".
I am getting an error when i try to fill company group variable.
BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2025 03:58 AM
sorry but you didn't share what debugging did you perform?
share screenshots of your form, variable configuration etc
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