Trying to write a reference qualifier for the approver field on a change request form.

wendellkubik
Kilo Contributor

 I need to pull from a Change_Approver group that contains all managers, and a Change_Approver_Delegates group that I must limit to the delegated approvers for the same department as the assigned_to in the current change request.

I'm using a script include to pull the members of the Change Approver group put I need to pull from two assignment groups and put the additional restriction of the same department on the delegates group.

Here is a sample of what i have but I am having trouble getting the script include to pule from two groups

javascript: new ACMEUserGroupUtils().getGroupMembers(gs.getProperty('change.approval.groups'), current.assigned_to) + "^department=" +current.assigned_to.department

 

script include below

 

var ACMEUserGroupUtils = Class.create();

ACMEUserGroupUtils.prototype = {

                initialize: function() {

                },

 

                /*

                                getGroupMembers() function returns the list of the group members of the

                                groupName passed as a parameter.

                */

                getGroupMembers: function(groupName, excludeUsers) {

                                var answer = [];

 

                                var grMember = new GlideRecord('sys_user_grmember');

                                grMember.addQuery('group.name', groupName);

                                grMember.query();

 

                                if (excludeUsers != '') {

                                                while (grMember.next()) {

                                                                if (excludeUsers.indexOf(grMember.user.toString()) == -1) {

                                                                                answer.push(grMember.user.toString());

                                                                }

                                                }

                                }

 

                                return 'sys_idIN' + answer.toString();

                },

 

 

                /*

                                isUserInGroup(): returns the user only if the user is a member of the group, empty otherwise.

                                Note: does not return boolean as function name would suggest.

                */

                isUserInGroup: function(user, group) {

                                //returns user if they are a mmember of the group.

                                var answer = '';

 

                                if (gs.getUser().getUserByID(user).isMemberOf(group)) {

                                                answer = user;

                                }

 

                                return answer;

                },            

 

                type: 'ACMEUserGroupUtils'

};

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Use this

 

javascript: new ACMEUserGroupUtils().getGroupMembers('Change_Approvers', current.requested_by) +'^OR'+ new ACMEUserGroupUtils().getGroupMembers('Change_Approver_Delegates', current.requested_by) + "^department=" + current.assigned_to.department

View solution in original post

29 REPLIES 29

I did not get you. Can you help me understand the difference between two statements.

Please correct this script

 

            getGroupMembers: function(groupName, excludeUsers, dept) {

                                var answer = [];

 

                                var grMember = new GlideRecord('sys_user_grmember');

                                grMember.addQuery('group.name', groupName);

if (dept)

grMember.addQuery('user.department','!=',dept);

 

                                grMember.query();

                                                while (grMember.next()) {

                                                                if (excludeUsers.indexOf(grMember.user.toString()) == -1) {

                                                                                answer.push(grMember.user.toString());

                                                                }

                                                }

                                return 'sys_idIN' + answer.toString();

                },

 

And use condition as

 

javascript: new ACMEUserGroupUtils().getGroupMembers('Change_Approvers',current.requested_by) +'^OR'+ new ACMEUserGroupUtils().getGroupMembers('Change_Approver_Delegates', current.requested_by,current.assigned_to.department)


Please mark this response as correct or helpful if it assisted you with your question.

Actually try this...This should be simple and no need to change the script

 

javascript: new ACMEUserGroupUtils().getGroupMembers('Change_Approvers', current.requested_by) +'^NQ'+ new ACMEUserGroupUtils().getGroupMembers('Change_Approver_Delegates', current.requested_by) + "^department=" + current.assigned_to.department

 

 


Please mark this response as correct or helpful if it assisted you with your question.

Thanks Sanjiv....it works.    I realized last night that I could have gone to a list and built a filter and then copy the script....but this works and I am very grateful.

We will reuse this javascript on other fields in some of our related tasks.

We also want to restrict the assigned to in approvals with this script.

Thanks also to Abinay who helped me with the quotes on the GroupName

If you are looking to get all the chnage approvers who are part of change approver delegates group then use this 

 

javascript: new ACMEUserGroupUtils().getGroupMembers('Change_Approvers', current.requested_by) +'^'+ new ACMEUserGroupUtils().getGroupMembers('Change_Approver_Delegates', current.requested_by) + "^department=" + current.assigned_to.department