Change Request Self Approval

jquinn24
Kilo Explorer

Hello!   We are setting up rules to prevent a user from approving his or her own Change Requests.   Currently, when a user creates a CR and assigns it to the appropriate group, that user can show up as an approver.

We've set up a business rule that sets the state of the Approval Record for that person to read "Not Valid".   We then created another business rule that prevents that user from modifying that particular record.   It runs against the sysapproval_approver table and reads as follows:


var cr = new GlideRecord ('change_request');

cr.addQuery('sys_id', current.document_id);

cr.query();

while (cr.next()){

  if (cr.requested_by == current.approver){

  current.setAbortAction(true);

  gs.addInfoMessage("You cannot approve a change for which you are the submitter.");

  }

}

It works just fine from the Approval record.   However, if the user selects the 'state' value in the Approval tab (related list) on the CR,   it can be modified, and thereby approve the CR.

My question is, can I disable the 'state' column on the Approval related list when the value is set to "Not Valid"?   I haven't been able to find info on this, so any help is greatly appreciated.   Thanks!

John Quinn

- CSC

3 REPLIES 3

waseem5
Kilo Expert

Hi John,



You can create an ACL to restrict write operation on 'State' field. The script in this ACL should check for the condition and return answer as true to enforce this restriction.



Please let me know if any more info is needed. Mark this answer if it helps.



Thanks


Waseem


The SN Nerd
Giga Sage
Giga Sage

You have a few options.


  • You can disable list edit on the Approves list (Configure > List Control > List Edit Type > Disable List Editing).
  • You can create an ACL for the 'list_edit' or 'write' operation on the 'state' field as mentioned above, using the script

answer = (current.sysapproval.requested_by != current.approver);




ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Deepak Ingale1
Mega Sage

var answer = [];


var appr = new GlideRecord('sys_user_grmember');


appr.addQuery('group.name', 'Your Group');


appr.query();


while(appr.next())


{


if(appr.user != current.requested_by)


  {


              answer.push(appr.user.sys_id);


  }


}


you can prevent to send approval mails to person who has requested it by using above code in approval activity


If you take care it at initial level   only, you don't require to wrire any addition BR or ACls