Autopoulation for variable list collector.

Atchutaram
Tera Contributor

Hi @everyone

I have a requirement where i need to auto populate all the groups from organization table to my catalog variable group.

I have a field in my table name as AD groups those should be auto populated in my catalog variable groups which is a list collector.

 

How can i do this?

 

Best Regards

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Atchutaram 

auto populate based on some filter?

you can use default value in that list collector and set your logic which sets the sysIds of those records

share some screenshots, list collector refers to which table

which other table are you referring here

what did you start with?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar , my requirement we have AD groups field in our u_organization table which consists of all groups from sys_user_group table. we fill them manually when any new organization is required. Now we have a catalog form for requesting a change in those groups. So when Organization name is selected in the form these group variable should be auto populated from AD group field which is in u_organization table,

 

BR

@Atchutaram 

so you can use onChange catalog client script with GlideAjax and bring those groups

Something like this

Script Include: It should be client Callable

var GetOrgADGroups = Class.create();
GetOrgADGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getADGroups: function() {
        var orgSysId = this.getParameter('sysparm_org_sysid');
        var result = [];
        if (!orgSysId)
            return '';
        var orgGR = new GlideRecord('u_organization');
        if (orgGR.get(orgSysId)) {
            // Assuming u_ad_groups is a List field storing sys_ids of sys_user_group
            var adGroups = orgGR.u_ad_groups + '';
            if (adGroups) {
                result = adGroups.split(',');
            }
        }
        return result.join(',');
    },
    type: 'GetOrgADGroups'
});

onChange Catalog Client Script on the reference variable which Refers to u_organization table

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
        // Optionally clear the group variable here
        g_form.clearValue('groupVariableName');
        return;
    }

    var ga = new GlideAjax('GetOrgADGroups');
    ga.addParam('sysparm_name', 'getADGroups');
    ga.addParam('sysparm_org_sysid', newValue);
    ga.getXMLAnswer(function(response) {
        var groupSysIds = response;
        if (groupSysIds) {
            // Set the list collector variable (replace 'groupVariableName' with your variable name)
            g_form.setValue('groupVariableName', groupSysIds);
        } else {
            g_form.clearValue('groupVariableName');
        }
    });
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar , do we need to give any sys_id in 

var orgSysId = this.getParameter('sysparm_org_sysid');
 
Best Regards