Prevent Change requester from approving their own Changes.

Steve Brown1
Tera Expert

Hi Community,

Using Helsinki - helsinki-03-16-2016__patch7-11-02-2016

Following a recent audit I need to prevent any Requester being able to Approve their own Change Requests.

I have read a couple of articles similar to my situation but they have been specific to a particular Assignment Group and my scripting skills are non existent to be able to turn their suggestions into something that works!!   I have also tried writing a Business Rules on the sysapproval_approver table but could not get this to work either.

I have attempted to change the below script from another post from 2014 to work in our Instance but I cannot get it to work - the best result was skipping the Peer check step of the workflow where an approval is required from the Assignment group of the Requester.

  1. answer = [];  
  2. var approvers = new GlideRecord('sys_user_grmember');  
  3. approvers.addQuery('group.name', 'IT Infrastructure Managers');  
  4. approvers.query();  
  5. while(approvers.next()) {  
  6.     if(approvers.user.toString() != current.requested_by.toString()) {  
  7.           answer.push(approvers.user.toString());  
  8.     }  
  9. }  

 

My version:

1. answer = [];  

2. var approvers = new GlideRecord('sys_user_grmember');  

3. approvers.addQuery('current.assignment_group');

4. approvers.query();  

5. while(approvers.next()) {  

6.   if(approvers.user.toString() != current.requested_by.toString()) {  

7.             answer.push(approvers.user.toString());  

8.       }  

9. }

I think the script is doing the following:

2 - Identifying the Group the Requester is in

3 - Is the Requester in the Assignment Group?

4 - ??

5 - ??

6 - If the Requester is in the Assignment Group

7 - ?? do something!

Many thanks in advance.

Steve Brown

1 ACCEPTED SOLUTION

There is an additional quotes in the current.assignment_group which will not make it work. I have done a minor update to code



answer = [];


var approvers = new GlideRecord('sys_user_grmember');


approvers.addQuery('group', current.assignment_group);   //Matches assignment group on change with the group membership table


approvers.query();


while(approvers.next()) {    


  if(approvers.user.toString() != current.requested_by.toString()) {


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


      }


}



I have tested this and it was working on my developer instance.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

20 REPLIES 20

I missed that the field was on Assignment group. Please try this code



answer = [];


var approvers = [];


approvers = current.assignment_group.u_change_approvers.split(',');   //Convert to array


for(var i=0; i<approvers.length; i++){


  if(approvers[i] != current.requested_by){     //Skip Requester


  answer.push(approvers[i]);


  }


}



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Shri8
Tera Contributor

Hi Alikutty,

 

Need a help on one requirement : If assigned to user is member of one group like Change Manager group then approval should not be triggered and error message should pop up.

Also, in authorize we have two level of approvals one to CI owner and next to Change Manager.

I tried with below code like when CI Owner is selected as Assigned to user, the approval should not be triggered but approval is triggered.

var gr = new GlideRecord('cmdb_ci');
gr.addQuery('sys_id', current.cmdb_ci);
gr.query();
if(gr.next()){
var ownerBy = gr.owned_by;
}
if(current.assigned_to == ownerBy){
current.setAbortAction(true);
gs.addErrorMessage('Assigned To cannot be the CI Owner');
}

 

Could you please help on as this is bit urgent.

where to implement this code?

Dominik Simunek
Tera Guru

Hi Stephen,



I have got similar requirement however it was necessary to restrict user who really clicked "Request Approval" from approving that change. Because ootb you can manually provide any value into Requested by field (I can enter there somebody else then me and click Request Approval and approve it if I am member of approval group).



We fulfilled the requirement with before insert business rule on Approval table (sysapproval_approver) that aborts the insert in case the approver for a change request is current user (who clicked Request Approval button) and state of change is Assess (= technical approval). In such way we still have also Group Approval (sysapproval_group) record created as ootb just one user approval (sysapproval_approver) record is not inserted if it is for the same user as the one clicking Request Approval.



Maybe somebody finds this helpful.



Best regards,


Dominik


Maks
Tera Guru

We've created a Business Rule at our company.

The change approval process still pulls everyone from 'Assignment Group' to the approval, but then the Business rule updates user's record to 'No Longer Needed'.

Business rule:

Table:Approval (sysapproval_approver)
Active:Yes

 

When to run:

Insert:Yes
Filter conditions:Source table is change_request
(AND) Approval for.Assigned to is same as Approver

 

Actions:

Set field values:State to 'No Longer Required'