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

Try using

javascript: new ACMEUserGroupUtils().getGroupMembers('Change_Approvers', current.requested_by)

Abhinay Erra
Giga Sage

You are missing quotes for the first parameter in the function

 

javascript: new ACMEUserGroupUtils().getGroupMembers('Change_Approvers', current.getValue('requested_by'))

wendellkubik
Kilo Contributor

Thanks ..this....really helped me solve my problem.   I am almost there

So I wrote my reference qualifier to use the same script include to pull users from both the Change_Approvers group and the Change_Approver_Delegate group and it is working.

I have a problem with the last part of javascript in this reference qualifier...syntax I think

 

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

I am trying to restrict the users from the Change_Approver_Delegates group to the same department as the current.assigned_to in the change request.

Do I have the parenthesis in the wrong place ?  Or should I use some other code to restrict to the same department?

I only want to apply the same department restriction to the second user group. Not the 'Change_Approvers' group. The Change_Approvers group will contain all managers who can approve for any department.

 

Thanks again for your help the 'Change_Approver' worked.

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

wendellkubik
Kilo Contributor

Thanks again....I think you are close

That code is only returning Change_Approvers and Change_Approver_Delegates in the same unit as the assigned_to

 

I would like the return ALL members of the Change_Approvers group and only Change_Approver_Delegates in the same unit as the assigned_to