Duplicate Approvals .... the ongoing dilemma

Wade Clairmont
Tera Guru

Yes, another question about duplicate approvals, but hoping there is still an answer for even these not so strange ones.

I have a workflow script that generates approvals based on selections from a multirow variable set within the RITM.

        Network Folder             Owner(Approver)

         w:/test                            Ricky Bobby

         h:/accounting                 William Bonnie

         i:/hr                                 Ricky Bobby

Now when the script (see attached) in the workflow runs to generate the approvals, and due to the nature of these approvals, I specifically need each one of these selected approvers to approve each part even though Ricky has 2, he must approve both separately.

Right now the system only generates 2 approvals, even though the approvals are for different variable selections in the RITM.

Is there anyway around the typical system removing duplicate approvals on catalog stuff?

Thanks in advance.

Wade

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Wade,

Just to clarify, any/all approvers are actually approving or rejecting the entire/same RITM, so that's why it's only going to generate an approval record for unique approvers - the audit/history will show that Ricky Bobby approved the request/RITM, not that he approved part of it / one row of the MRVS.  You could try to find and modify the OOB script/Business Rule that is generating the approval records from the workflow activity/answer array, but you can also generate the approval records yourself in a Run Script activity instead of using the Approval - User activity.  Here's a script I've used to do this.

var mrvs = current.variables.approval_mrvs; //internal name of the MRVS
var rowCount = mrvs.getRowCount();
for (var i=0; i<rowCount; i++) { //for each row in the MRVS
	var row = mrvs.getRow(i); 
	if(row.v_approval_user != ''){ //if the approver variable is populated
		var app = new GlideRecord('sysapproval_approver');
		app.newRecord();
		app.approver = row.v_approval_user;
		app.sysapproval = current.sys_id;
		app.source_table = 'sc_req_item';
		app.document_id = current.sys_id;
		app.state = 'requested';
		app.insert();
	}
}

I haven't tried using this to add the same user more than once, but if it doesn't then it should be easy enough to find the BR that is preventing the creation of an approval record when one for the same approver and approval already exists.

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Hi Wade,

Just to clarify, any/all approvers are actually approving or rejecting the entire/same RITM, so that's why it's only going to generate an approval record for unique approvers - the audit/history will show that Ricky Bobby approved the request/RITM, not that he approved part of it / one row of the MRVS.  You could try to find and modify the OOB script/Business Rule that is generating the approval records from the workflow activity/answer array, but you can also generate the approval records yourself in a Run Script activity instead of using the Approval - User activity.  Here's a script I've used to do this.

var mrvs = current.variables.approval_mrvs; //internal name of the MRVS
var rowCount = mrvs.getRowCount();
for (var i=0; i<rowCount; i++) { //for each row in the MRVS
	var row = mrvs.getRow(i); 
	if(row.v_approval_user != ''){ //if the approver variable is populated
		var app = new GlideRecord('sysapproval_approver');
		app.newRecord();
		app.approver = row.v_approval_user;
		app.sysapproval = current.sys_id;
		app.source_table = 'sc_req_item';
		app.document_id = current.sys_id;
		app.state = 'requested';
		app.insert();
	}
}

I haven't tried using this to add the same user more than once, but if it doesn't then it should be easy enough to find the BR that is preventing the creation of an approval record when one for the same approver and approval already exists.

Wow, never would have thought of taking the approvals outside of the workflow object to a script.  Once I added wait for condition on the approvals then it worked like a charm.

You rock!  Thanks for you help!

You are welcome!