control visibility of assignment group based on logged in user

Shivani29
Mega Guru

Hi All,

 

I have a scenario where if logged in user is a part of wpt and opens new incident form can only see groups related to wpt. Also, if it is not  a new form and incident is assigned to wpt then along with wpt groups , group A should also come in the assignment group so that they can re assign the tkt to group A, if required. I have written script include and client script, added logs as well, script include is passing groups correctly to client script but in assignment group field all the groups are visible. Below are the scripts:

Client Script:

 

function onLoad() {
    //Type appropriate comment here, and begin script below
    if (g_form.isNewRecord()) {
        g_form.addInfoMessage('New Form');
        var ga = new GlideAjax('assignment_group');
        ga.addParam('sysparm_name', 'getVisibleGroups');
       ga.getXML(assignmentGroup);
        function assignmentGroup(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            g_form.addInfoMessage(answer);
            g_form.setReferenceQual('assignment_group',answer);
           
        }
    }
}
 
Script Include:
 
var assignment_group = Class.create();
assignment_group.prototype = {
    initialize: function() {},
    getVisibleGroups: function(){
        var user =  gs.getUserID();

        gs.log('shivani logged in user '+user);
        var groupIds = [];

        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user',user);
        gr.addEncodedQuery('groupLIKEwpt');
        gr.query();
        gs.log('shivani group count '+gr.getRowCount());
        if (gr.next()){
            gs.log('inside if query');
            var groupUser = new GlideRecord('sys_user_group');
            groupUser.addEncodedQuery('nameLIKEwpt^active=True');
            groupUser.query();
            gs.log('shivani counting row '+groupUser.getRowCount());
            while(groupUser.next()){
            groupIds.push(groupUser.getUniqueValue());
            }}
            else{
                gs.log('inside else');
                var allGroup = new GlideRecord('sys_user_group');
                allGroup.addEncodedQuery('active=true');
                allGroup.query();
                gs.log('all groups count'+allGroup.getRowCount());
                while(allGroup.next()){
                groupIds.push(allGroup.getUniqueValue());
                }}
                gs.log('SHivani Group ID '+groupIds);
                return "sys_idIN" + groupIds;
    },

    type: 'assignment_group'
};
 
Your help is much appreciated.
 
Thanks and Regards,
Shivani
1 ACCEPTED SOLUTION

Shivani29
Mega Guru

Hi All,

 

Thanks for your efforts and time. I managed to resolve this issue by sending the incident number from reference qualifier and in script include i gliderecord the incident table to check if record with this number exists or not. it it does not exist, it is a newReord and accordingly i run the entire script.

 

Regards,

Shivani.

View solution in original post

16 REPLIES 16

Shruti
Mega Sage
Mega Sage

Hi,

Update the reference qualifier of assignment group field and deactivate the on load client script

javascript: new assignment_group().getVisibleGroups();

Hi Shruti,

 

I tried this but was unable to check in script include if this is new form or not. Could you please help me out with the syntax to check for new form in script include.

 

Regards,

Shivani

If you are using client script. Use client callable script include 

var assignment_group = Class.create();
assignment_group.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    initialize: function() {},
    getVisibleGroups: function() {
        var user = gs.getUserID();

        gs.log('shivani logged in user ' + user);
        var groupIds = [];

        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', user);
        gr.addEncodedQuery('group.nameLIKEwpt');
        gr.query();
        gs.log('shivani group count ' + gr.getRowCount());
        if (gr.next()) {
            gs.log('inside if query');
            var groupUser = new GlideRecord('sys_user_group');
            groupUser.addEncodedQuery('nameLIKEwpt^active=True');
            groupUser.query();
            gs.log('shivani counting row ' + groupUser.getRowCount());
            while (groupUser.next()) {
                groupIds.push(groupUser.getUniqueValue());
            }
        } else {
            gs.log('inside else');
            var allGroup = new GlideRecord('sys_user_group');
            allGroup.addEncodedQuery('active=true');
            allGroup.query();
            gs.log('all groups count' + allGroup.getRowCount());
            while (allGroup.next()) {
                groupIds.push(allGroup.getUniqueValue());
            }
        }
        gs.log('SHivani Group ID ' + groupIds);
        return "sys_idIN" + groupIds;
    },

    type: 'assignment_group'

});

Hi Shruti,

 

Script include is client callable and I am getting answer in client script, but only issue is not able to make those groups visible in assignment group field.

 

Regards,

Shivani