Need to have assignment group only show groups that the assigned to is a member of

SSuddarth
Tera Contributor

When "Assigned to" is filled out on any forms (SCTask, Incident, etc) I need to be able to filter the "Assignment group" so that it only shows the groups the Assigned to is a member of.

 

Is there a way to do this? Client Script? Advanced Filter?

2 ACCEPTED SOLUTIONS

swathisarang98
Giga Sage
Giga Sage

Hi @SSuddarth ,

 

OOTB when you select assignment group, In assigned to you will get the member of the assignment group selected if you want it in reverse then you can try the below possible ways,

 

https://www.servicenow.com/community/itsm-forum/when-assigned-to-field-is-selected-then-groups-will-... 

 

another way is to create script include and call it from reference qualifier,

 

Tried forAssignment group field in Task table ,

Reference qualifier,

swathisarang98_0-1715290108706.png

 

 

javascript: new getAssignedToGroup().getGroups(current.assigned_to);

 

 

 

Script Include:

swathisarang98_1-1715290137679.png

 

 

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

    getGroups: function(sysId) {
        
        gs.info('sysid ' + sysId);
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', sysId);
        gr.query();
        var arr = [];
        while (gr.next()) {
            arr.push(gr.getValue('group'));
        }
        gs.info('array ' + arr);
        return 'sys_idIN'+ arr.toString();
    },


    type: 'getAssignedToGroup'
});

 

 

 

Result:

swathisarang98_2-1715290200480.pngswathisarang98_3-1715290219704.png

 

Note: As you are doing this on Task table variable Assignment group This will be Global change .

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

 

View solution in original post

Hi @SSuddarth ,

 

I have updated the script include please give it a try,

 

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

    getGroups: function(sysId) {

        gs.info('sysid ' + sysId);
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', sysId);
        //gr.addExtraField('group.type','itil');
        gr.query();
        var arr = [];
        while (gr.next()) {

            if (gr.group.type.indexOf(gs.getProperty('SysId.itil.type')) > -1 ) //created a system property SysId.itil.typeand stored type itil backend sys id 
            {
                gs.info('type', gr.group.type);
                gs.info('inside if');
                arr.push(gr.getValue('group'));
            }

        }
        gs.info('arra' + arr.toString());
        if (arr.length == 0) {
            gs.info('inside false side');
            return 'sys_idIN' + '';
        } else {
            return 'sys_idIN' + arr.toString();
        }
    },
    type: 'getAssignedToGroup'
});

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

4 REPLIES 4

swathisarang98
Giga Sage
Giga Sage

Hi @SSuddarth ,

 

OOTB when you select assignment group, In assigned to you will get the member of the assignment group selected if you want it in reverse then you can try the below possible ways,

 

https://www.servicenow.com/community/itsm-forum/when-assigned-to-field-is-selected-then-groups-will-... 

 

another way is to create script include and call it from reference qualifier,

 

Tried forAssignment group field in Task table ,

Reference qualifier,

swathisarang98_0-1715290108706.png

 

 

javascript: new getAssignedToGroup().getGroups(current.assigned_to);

 

 

 

Script Include:

swathisarang98_1-1715290137679.png

 

 

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

    getGroups: function(sysId) {
        
        gs.info('sysid ' + sysId);
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', sysId);
        gr.query();
        var arr = [];
        while (gr.next()) {
            arr.push(gr.getValue('group'));
        }
        gs.info('array ' + arr);
        return 'sys_idIN'+ arr.toString();
    },


    type: 'getAssignedToGroup'
});

 

 

 

Result:

swathisarang98_2-1715290200480.pngswathisarang98_3-1715290219704.png

 

Note: As you are doing this on Task table variable Assignment group This will be Global change .

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

 

The script include worked perfectly! Thank you!

 

What if I want to include a second condition such as "Type is itil"?

Hi @SSuddarth ,

 

I have updated the script include please give it a try,

 

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

    getGroups: function(sysId) {

        gs.info('sysid ' + sysId);
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', sysId);
        //gr.addExtraField('group.type','itil');
        gr.query();
        var arr = [];
        while (gr.next()) {

            if (gr.group.type.indexOf(gs.getProperty('SysId.itil.type')) > -1 ) //created a system property SysId.itil.typeand stored type itil backend sys id 
            {
                gs.info('type', gr.group.type);
                gs.info('inside if');
                arr.push(gr.getValue('group'));
            }

        }
        gs.info('arra' + arr.toString());
        if (arr.length == 0) {
            gs.info('inside false side');
            return 'sys_idIN' + '';
        } else {
            return 'sys_idIN' + arr.toString();
        }
    },
    type: 'getAssignedToGroup'
});

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

This works perfectly! Thank you so much!