Add groups to variable field through automation.

Atchutaram
Tera Contributor

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.

8 REPLIES 8

Ashish Parab
Mega Sage

Hello @Atchutaram ,

 

You can do this by creating an onChange catalog client script and a GlideAjax call. Please share what you have tried earlier.

 

Company group table is a custom table, right? And the AD group variable is of which type?

 

Please mark this response as Correct and Helpful if it assists you.


Thanks,
Ashish

Hi @Ashish Parab , Currently we do have a runscript for automatically adding AD groups to user groups profile. Yes, Company table is custom table and AD group variable is string type variable in custom table record,

umaaggarwal
Giga Guru
Giga Guru

Hello,

 

  • You need to use on change client script on your table on the chnage of 'Company groups'. 
  • Pass this value to glide ajax script include function
  • in glide ajax , glide record to the ref table (i.e. Company groups) and get the value of org group for each record and keep adding the value to a string field ( dispaly value not the sys id)
  • do this for all the records you passed in script include
  • return the final string to client script 
  • set the value of AD  group to that string

 

Try to write the client script and script include and share the code if you get stuck somewhere.

 

Thanks!

Uma

Hi @umaaggarwal 

this is the script include: 

var GetOrgValues = Class.create();
GetAADValues.prototype = Object.extendsObject(AbstractAjaxProcessor, {

GetAADValues : 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 new JSON().encode(result);
}
});
 
 
This is client script:
 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        var selectedIDs = g_form.getvalue('u_company_groups');
        if (!selectedIDs) return;
        var selectedArray = selectedIds.split(',');
        var currentADGroup = g_form.getValue('vo_ad_groups');

        var ga = new GlideAjax('GetOrgValues ');
        ga.addParam('sysparm_name', getAADList);
        ga.addParam('sysparm_ids', selectedIDs);
        ga.getXMLAnswer(function(response) {
            if (!response) return;
            var aadvalues = JSON.parse(response);
            var newADGroupValue = currentADGroup;
            if (aadvalues.length > 0) {
                if (newADGroupValue && newADGrouoValue.length > 0) {
                    newADGroupValue += ',';
                }
                newADGroupValue += aadvalues.join(',');
            }
            g_form.setValue('vo_ad_groups', newADGroupValue);
        });
        return;

    }