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 had to leave some reference qualifiers at the beginning that I used for the assigned_to on the change_request

I just realized that the assigned_to is on the task table and is shared by tasks and change_request

I used new querry +^NQ' to call my script util like I did earlier for the Approver field but it doesn't seem to be working

This is what i have now for the reference qualifier

javascript: "sys_id!=" + current.u_tester + "^sys_id!=" + current.u_approver +^NQ'+ new ACMECTaskTestUtil().excludeFunction()

Any ideas?

javascript: new USAACTaskTestUtil().excludeFunction() + "^sys_id!=" + current.u_tester + "^sys_id!=" + current.u_approver

The reference qualifier above is now working on the Change_task_type test so the script include is working

It also works on the test task if I call the script util by itself

javascript: new USAACTaskTestUtil().excludeFunction()

However, when I add my origianl queries on the end....this reference qualifier no longer works on the parent change_request

any ideas?  should I try NQ new querry?

also tried without the carrot ^ 

javascript: new USAACTaskTestUtil().excludeFunction() + "sys_id!=" + current.u_tester + "^sys_id!=" + current.u_approver

and the rules did not work on the change request and broke the assigned to restriction on the script util

I'm out of ideas

I figured it out.  using things you already told me before.

 

I had to create a another script include to make it work.

See below

javascript: new USAATaskTypeUtil().excludeFunction() + '^NQ' + new USAACTaskTestUtil().excludeFunction()

You can use same script include. Just create a new function in the script include.