Is there a way to limit the number of approvals for the same approver

Cupcake
Mega Guru

I wanted to know if there is a way that I can limit the # of approvals that an approver receives.

So I have a catalog item that uses a table. The table houses a few hundred databases, and on that table there is a field called Owned by which would be the approver.

On the form a customer can select up to 5 databases at one time and what I am trying to do is if Database # 1, and Database #4 - all have the same owned by - I only want that approver to get one approval and NOT 3. The workflow must also wait for all of the approvers to approve before the task generates.

find_real_file.png

Thank you,

Karen

4 REPLIES 4

Andrew Wortham
Kilo Guru

Hey Karen,



This can absolutely be done.   Can we see what your workflow currently looks like?   Do the approvals need to happen one after another or can they all happen at the same time?   If you make the approval a single approval event that waits for all approvers to approve with the database.owner as the approvers, you should be able to get where you want with only a single approver going to each user even if they own all 5 databases.



Please provide include your specific current approach, and we can provide further advice / feedback! There are likely many ways to achieve what you are looking for.



Best,


Andrew


I will provide this as soon as I clarify with the customer. I don't think they thought about that. I need to know from them also if there are 5 approvers and 1 rejects then what is there expectation.


So that just opened my mind further - it might be in our best interest to leave it as a normal workflow because when I think about the rejection piece and the approver might be responsible for 3 of the 5 databases and they want to only reject 1 out of their three that will be an issue.



This is currently how the form is setup:


find_real_file.png



Thank you for responding.



I will get the wf information to you as soon as they confirm what they want.



Karen


Good day Andrew,


        I have the answsers to the questions:



1. All the approvals can generate at the same time,


2. The customer is okay with the entire request being rejected if one approver rejects



I am having a little difficulty with the script inside of the workflow. So in the screenshot below there are 5 different fields as you can see. All of the information about the database is listed in a table that also includes the approver (owned by).



find_real_file.png



Here is what I have in my script inside of the business approval - it is only giving the approval name for the first DB for every one


var cis = current.variables.ibcprd_nonsec_db1.toString().split(",") || current.variables.ibcprd_nonsec_db2.toString().split(",") || current.variables.ibcprd_nonsec_db3.toString().split(",") || current.variables.ibcprd_nonsec_db4.toString().split(",") || current.variables.ibcprd_nonsec_db5.toString().split(",");


answer = [];


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


      var a = new GlideRecord("cmdb_ci");


      a.get(cis[i]);


      if(a){


              answer.push(a.owned_by.sys_id);


      }


}



find_real_file.png


Hello Karen,


Those are very reasonable answers to the questions and are what I would recommend.



When it comes to the script my understanding is that you are just looking grab the 5 database owners.   I am a little bit confused by your approach.   What does logging "cis" show?


Is there a reason you can't do:



var answer = [];


answer.push(current.variables.ibcprd_nonsec_db1.owned_by.sys_id);


answer.push(current.variables.ibcprd_nonsec_db2.owned_by.sys_id);


answer.push(current.variables.ibcprd_nonsec_db3.owned_by.sys_id);


answer.push(current.variables.ibcprd_nonsec_db4.owned_by.sys_id);


answer.push(current.variables.ibcprd_nonsec_db5.owned_by.sys_id);



Or something along those lines?   From the looks of the screen shot "ibcprd_nonsec_db1" looks to be a reference field rather than a list collector, so "ibcprd_nonsec_db1.toString()" Is going to provide you a single sys_id so the split would not be necessary.



For learning sake:



It looks like you are defining the variable cis using a conditional which is not standard JS, did you mean to concatenate each of those fields?



something like



var cis = '';


if(current.variables.ibcprd_nonsec_db1.toString() != '') {


  cis += current.variables.ibcprd_nonsec_db1.toString()


}


if(current.variables.ibcprd_nonsec_db2.toString() != '') {


  cis += current.variables.ibcprd_nonsec_db2.toString()


}


etc…



Then once you get your list of database sys_ids you then go through and create a glide record to them, which as mentioned above should be able to be dot walked into from the beginning instead, but the code does look correct for doing it that way.  


var cis = current.variables.ibcprd_nonsec_db1.toString().split(",") || current.variables.ibcprd_nonsec_db2.toString().split(",") || current.variables.ibcprd_nonsec_db3.toString().split(",") || current.variables.ibcprd_nonsec_db4.toString().split(",") || current.variables.ibcprd_nonsec_db5.toString().split(",");


answer = [];


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


      var a = new GlideRecord("cmdb_ci");


      a.get(cis[i]);


      if(a){


              answer.push(a.owned_by.sys_id);


      }


}



Hopefully that makes sense / helps!



Best,


Andrew