Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

show the groups only where the requested by is a part of

suprajam
Tera Contributor

Hey, i have a reference field which i have to populate with the groups for which the "requested by" is a part of "only". Help please.

12 REPLIES 12

@Gunjan Kiratkar hey in the variable the group i have to refer will be sys group so the group from the script include will vary.

Use below code 

 

var getAjax = Class.create();

getAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

    getGroups: function(getReq) {

        var groupArr = [];

        var uID = getReq;

        var grmember = new GlideRecord('sys_user_grmember');

        grmember.addQuery('user', uID);

        grmember.addQuery('group.active', true);

        grmember.query();

        while (grmember.next()) {

            groupArr.push(grmember.group.toString());

        }

        return 'sys_idIN' + groupArr;

    },

    type: 'getAjax'

});


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

hey im still not getting it @Gunjan Kiratkar