- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 03:34 AM
Requirement : I have a Lookup select box field called "Division" and based on the selection of the Division Value We have to autopopulate the "Secondary LDAP groups" into the "AD Group" field for their related records
But as per the screenshot provided, if you select ACQI as division in the corresponding Secondary LDAP Groups there were some duplicates also, So we need to remove those duplicate values and set the unique values into the "AD Group" field.
Please help me out on this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 05:22 PM
Hi @Sai18 ,
Basically you need to create a client script on change for division field
Call a script include where you need to Use the ArrayUtil class to remove duplicates from the "Secondary LDAP groups" and set the unique values in the "AD Group" field.
The script should look like below-
Client-
var ga = new GlideAjax('LDAPGroupProcessor');
ga.addParam('sysparm_name', 'getUniqueLDAPGroups');
ga.addParam('sysparm_division', newValue);
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
// Set the unique LDAP groups into the "AD Group" field
g_form.setValue('ad_group', answer);
}
});
Script include-
var LDAPGroupProcessor = Class.create();
LDAPGroupProcessor.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUniqueLDAPGroups: function() {
var division = this.getParameter('sysparm_division');
var ldapGroups = [];
var gr = new GlideRecord('your_table_name'); // Replace with your table name
gr.addQuery('division', division);
gr.query();
while (gr.next()) {
var groups = gr.getValue('secondary_ldap_groups').split(',');
ldapGroups = ldapGroups.concat(groups);
}
// Remove duplicates
var uniqueGroups = ArrayUtil.unique(ldapGroups);
return uniqueGroups.join(',');
}
});
Note- Please adjust the field names as per your instance.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 03:45 AM
Thanks for your help out on this
initially it wont work but I have updated script slightly and working fine
Client Script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 03:57 PM
I would leverage ArrayUtil and the unique function as a way to handle gathering data that might have duplicates and de-duplicating it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 05:22 PM
Hi @Sai18 ,
Basically you need to create a client script on change for division field
Call a script include where you need to Use the ArrayUtil class to remove duplicates from the "Secondary LDAP groups" and set the unique values in the "AD Group" field.
The script should look like below-
Client-
var ga = new GlideAjax('LDAPGroupProcessor');
ga.addParam('sysparm_name', 'getUniqueLDAPGroups');
ga.addParam('sysparm_division', newValue);
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
// Set the unique LDAP groups into the "AD Group" field
g_form.setValue('ad_group', answer);
}
});
Script include-
var LDAPGroupProcessor = Class.create();
LDAPGroupProcessor.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUniqueLDAPGroups: function() {
var division = this.getParameter('sysparm_division');
var ldapGroups = [];
var gr = new GlideRecord('your_table_name'); // Replace with your table name
gr.addQuery('division', division);
gr.query();
while (gr.next()) {
var groups = gr.getValue('secondary_ldap_groups').split(',');
ldapGroups = ldapGroups.concat(groups);
}
// Remove duplicates
var uniqueGroups = ArrayUtil.unique(ldapGroups);
return uniqueGroups.join(',');
}
});
Note- Please adjust the field names as per your instance.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 03:45 AM
Thanks for your help out on this
initially it wont work but I have updated script slightly and working fine
Client Script :