Slinger's Thoughts

February 27, 2013

Setting “Cancel on first rejection” on an SPD workflow.

Filed under: 2010, SharePoint, SharePoint Designer, Workflow — slingeronline @ 10:57 am

I’ve been working on a workflow for a department at work.  It turns out to be a bit complicated, since it is a multi-step approval workflow and I need to clean up the task assignment e-mails sent.  So here is how the workflow needs to work.  When an item is submitted to a library, the approval workflow starts.  One user has an approval task.  If that one user rejects the submitted item the workflow is over.  If he approves, then 5 additional people need to approve the workflow. There is no particular order, so running the second stage of the approval in parallel is ideal.  If any one of those individuals reject the item then the workflow is over.  There must be 6 approvals in total for the item to be approved.  Doing a two stage approval workflow in SharePoint designer is fairly easy, and for clarity I will add how to do that in this post as well.

First we need to add the approval workflow to our library. So crank up SharePoint Designer and away we go.  Add a workflow to our library, and add the action “Start Approval Process”

ScreenHunter_01 Feb. 27 09.19

We need to pick our users for each stage of the workflow, so click the link that says “these users” on the workflow step which will bring up the user selection and notification dialog.

ScreenHunter_01 Feb. 27 09.24

This form mimics the functionality of the out of the box approval workflow with a handful of exceptions. The screen above is pretty much the same as the screen below. One notable exception is the area highlighted in red. We’ll get to that in a few minutes.

ScreenHunter_01 Feb. 27 09.29If we want to add a second stage to our out of the box workflow we can click on the “Add a new stage” link. To do the same thing in our SharePoint designer workflow, click on this icon ScreenHunter_01 Feb. 27 09.24 in the “Select Task Process Participants” screen and then click “Insert Assignment Stage.” For our demonstration, we are going to have Wash, Kaylee, and Inara approve our document before it moves on to Mal. If any of the first three reject the document, Mal will never see it. So we’ll add the first three as a parallel approval, and stage two doesn’t really matter since only one person will see it. Once we have our users selected and have an appropriate e-mail constructed, we click OK and we are all set. Let’s go ahead and test out our workflow. Add a document to the library we created the workflow on, and start the workflow. As one of our users, reject the document. If we had used the out of the box workflow we could have selected the option to “Automatically reject the document if it is rejected by any participant.” If one person cancels the workflow, all of the other tasks are cancelled also. So let’s say Wash doesn’t approve, but Kailey and Inara are okay with the form. Remember, we don’t want Mal to be bothered if the rest can’t agree. So Wash rejects the form, and the other two approve it, and we are left with this.

ScreenHunter_01 Feb. 27 10.02

Well phooey, even though Wash didn’t like the form, it still went to Mal. How do we fix that in our SharePoint Designer Workflow? While I was researching the issue I found this blog post about it. It’s not bad, but I figured there had to be a better way, especially if we ever want to change the setting back. Turns out there is.  There is a variable that the workflow checks, that is never set if we are strictly using SharePoint designer.  All we need to do is set that variable.  Here’s a tiny little catch, we need to set the variable before the approval step starts, but the workflow variable doesn’t exist until after we add the start approval process step. That’s OK, we can just move it.

Go back into SharePoint designer and add a step to set a workflow variable.

ScreenHunter_01 Feb. 27 10.17

Click on the “workflow variable” link and select “Variable:CancelonRejection” then click on “value” and set it to “yes.” So now we have set the variable, but we need to do it before the approval process kicks off, not after. This is actually as simple as moving the step up. It sets the variable first, then starts the approval process. The reason that we can’t manually add the variable before we add the approval process step is because the approval process step adds all of the variables and if it already exists when we add the step, the variable created and used by the step would actually be “Variable:CancelonRejection1.” Now that we have added the condition, let’s try our workflow again. As soon as one person rejects the document, all of the other workflow tasks are cancelled, and no new tasks are added.

ScreenHunter_01 Feb. 27 10.43

Now that we have it working the way we want, we can go about cleaning up the e-mails that are sent by the approval process to make them easier to read, which incidentally is why we wanted to create the workflow in SharePoint Designer anyway.

p.s. The other variable that we can set this way is CancelonChange.  Works the same way.

 

 

 

 

Advertisements

11 Comments »

  1. Reblogged this on Sutoprise Avenue, A SutoCom Source.

    Comment by SutoCom — March 1, 2013 @ 11:44 am

  2. Love the Firefly character names in the example!

    Comment by prcGTI — November 1, 2013 @ 4:41 pm

  3. This answered a question I had! Thank you. Something related — during this process, how do I grab the identity of the person currently approving/rejecting so I may reference it in the email? For instance, our approval workflow goes to Supervisor, then Manager. If rejected, I want the email to say, “Your request was rejected by [whoever rejected]. Please contact them to discuss.”

    I’ve looked in Workflow variable and Workflow:Context but nothing seems to be ringing a bell as IT. ??

    Comment by amygeekery — March 28, 2014 @ 4:10 pm

  4. If Current Item:Name contains (ignoring case) Add
    Start Approval (16) process on Current Item with user
    then Set Variable: CancelonRejection to Yes
    Any idea what I am doing wrong?

    Comment by Jim Huseman — May 1, 2014 @ 12:32 pm

    • To clarify I have a two stage approval process that should end when stage 1 rejects it but always goes to stage 2 creating massive overhead.

      Comment by Jim Huseman — May 1, 2014 @ 12:33 pm

      • For the two stage approval process, do you have one task with multiple stages? or two tasks? You might need to break it up into two tasks, with a condition between them that will end the wf or move on to the 2nd task.

        Comment by Jay Strickland — May 2, 2014 @ 9:13 am

  5. I have the user set, I just didn’t want to disclose their name.

    Comment by Jim Huseman — May 1, 2014 @ 12:32 pm

  6. Thanks for this method ! great job

    Comment by chris — July 8, 2014 @ 7:07 am

  7. Hi. I’m trying to implement cancel on rejection in my approval workflow as you describe above. It does initially look like it works because it sets the workflow outcome to Rejected and sends the rejection email to the initiator. However, when I look at the workflow status for that item in my browser, I see that the workflow is still running. It doesn’t seem to end when using Cancel on Rejection. Did you encounter this issue? Do you have any suggestions? Thanks!

    Comment by Andrea — December 1, 2014 @ 3:21 pm

  8. Reblogged this on Prasad's Blog.

    Comment by Prasad Gavande — June 24, 2015 @ 10:40 pm

  9. Does the 3rd screenshot exist in SPD 2013?

    Comment by Brian — December 23, 2015 @ 9:37 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: