Re: How to combine Approval activities for same approver

nicolemccray
Tera Expert

I have an issue where the same user has to approve twice, because the request is for 2 different roles (even though the Approver is the same person).   Is there a script I can use to check if user has already approved?.   I would like to do this in the workflow rather than using a Business Rule.   I've tried adding a run script, but system is still generating 2 approvals for the same user:

      if (current.document_id || current.sysapproval){  

 

              var app = new GlideRecord('sysapproval_approver');  

              app.addQuery('sysapproval', current.sysapproval);  

              app.addQuery('sys_id','!=',current.sys_id);  

              app.addQuery('approver', current.approver);  

              app.addEncodedQuery('state=requested^ORstate=not requested^ORstate=approved');  

              app.orderBy('state');  

              app.query();  

              while(app.next()){  

                      //If previous approval is found set this approval to 'approved'  

                      if (app.state == 'approved'){  

                              current.state = 'approved';  

                              current.comments = "Approval marked by system as 'Approved' due to a previous approval on the same record by the same user.";  

    }

  }

}

find_real_file.png

3 REPLIES 3

Dominik Simunek
Tera Guru

Hi Nicole,



Are you running the script you shared in that highlighted activity? Do you want to apply that rule to all the approvals in the workflow - so even those Role Owner approvals? Do you want to still have the approval record being created in the system or is it fine if it is basically skipped in the workflow as approved?



What I would do probably is that in the   Approval - User activity I would write a script to populate the approvers in field "Additional approvers script" and the script would do following:


1) grab the approver you are using now


2) check if such approver has already approved approval (since it is workflow I guess all previous approvals must be approved/rejected so I do not need to check for Requested or Not Yet Requested I guess)


3) if such approver already approved this record, I would add nobody to the list of approvers and so the activity would default to "approved" path I believe



It is not final solution proposal but maybe it helps you.


Best regards,


Dominik


Yes, the script I have noted above is the script I am running in the activity in the red box.   I want it to apply to all Role Owner Approvers (so none of them have to approve twice).



This is what I have in the Approval - User Activity:



var gr = new GlideRecord('u_database_roles');


gr.get(workflow.scratchpad.role_names[0]);


answer = [];


answer.push(gr.u_role_owner);




How can I modify this to check whether they have already approved?   I am fairly new to scripting, so will need help with the actual script itself. I still want the approval record to be created so that it shows in the history, but would like it to auto approve with the comment:   "Approval marked by system as 'Approved' due to a previous approval on the same record by the same user.";


Hi Nicole,



If you want to still create it and approve it, you will need to build a business rule for that I believe (or you would need to create a copy of Approval - User workflow activity and change its behavior). This is because Approval - User activity will create the approvals and then it is basically waiting for them to be approved/rejected before moving on in the workflow. Unfortunately I don't think it provides a way how to directly approve the approval within it.



So I would create a business rule on "sysapproval_approver" table with condition so that it executes only for your special item and running similar script you already wrote basically before insert. You need to check if the workflow is properly continued then (it might not react to the fact you inserted the approval directly as approved) and also that the notification is not sent out to the approver since it is already approved.



But still, if you want to approve them anyway, I would still prefer to not create those approvals at all and instead I would just wrote a comment to the work notes of the item saying something like "Approval for <user> marked by system as 'Approved' due to a previous approval on the same record by the same user."



Best regards,


Dominik