Two Easy Ways to Calculate Working Days Inside a SharePoint Workflow
Contents
Introduction
Are you able to calculate inside a SharePoint Workflow?
I’m in the midst of two different major SharePoint Workflows for clients right now, one of them being an HR New Hire Onboarding request and approval process. One small but critical requirement of the process was that each level of approval needed a two business day wait period. I’ve seen different suggested solutions for this on the internet, but nothing super easy and in the context of a workflow, or would fully work in my situation. So I thought I’d share a couple of quick and easy ways to accomplish this.
Background of My Solution
Before I get into the specifics, let me just give a quick rundown of the different parts of my process that I have going on.
■InfoPath web form published to a SharePoint form library
■SharePoint data connection library containing a UDC data connection via Secure Store to the User Profile Service, thanks claims authentication
■SharePoint Reusable workflow (as I’m using the workflow in two different libraries)
■SharePoint list for the business day calculation
All of the approval is tracked in the InfoPath form, not the workflow. The process goes like this:
1.A manager comes to the HR site and fills out a new hire request form
2.HR reviews the form, and starts the approval workflow
3.The workflow sends out email for level 1 approver
4.Wait 2 business days
5.If not approved, look up level 2 approver
6.Email level 2 approver
7.Wait 2 business days
8.etc…
The process continues until we hit the CEO at which case we stop and redirect to HR. None of all that matters per say, but I just wanted to give you some context of where we’re at. What I needed was to figure out how to calculate and set a future date 2 working days from that current point in time, which there would be multiple in the same workflow context. But I also needed to set the 2 working days for the END of the day at 5pm.
Why Other Solutions Didn’t Work
SharePoint workflow (neither 2007, 2010 or 2013) has a built-in action to do the calculation, similar to like a NETWORKDAYS formula in Excel. Ok, so then I turned to posts online talking about using a calculated column to do the formula. Cool I think we’re on to something. But as I got to thinking, it wouldn’t fly. So I can create a calculated column on my form library, but that is only updated when the form itself is updated. Besides, the Created and Modified won’t work either, because neither would be the exact current date/time. I also didn’t have to write some complex Visual Studio based workflow. No thanks. So I devised a similar solution using a separate SharePoint list whose sole purpose is to do the calculation. It’s extremely simple and works just fine.
Solution 2 – Use Workflow Extensions in Context
What if you don’t want to use another list, and purely want a workflow? Do I have to write a Visual Studio workflow? Nope! Yes, you still have to use custom code, but guess what. There are multiple software vendors that make workflow extensions and guess what they can do – provide an action to execute code in-line at runtime! I haven’t researched extensively, but I know of these two in no particular order:
1.Harepoint Workflow Extensions
2.SharePoint Workflow Activity Extensions by Virto Software
Just add your favorite execute custom code action, paste in the C# code to do the calculation, and you’re ready to go!
A Free Alternative – Not Tested
I’ll freely admit I haven’t tested this, but it would work in theory. In the free edition of the Harepoint extensions, it has some DateTime functions. One I noticed was:
![]()
So you could in theory, do all the formula with workflow actions. This returns a numeric value for the day of the week (1 for Sunday, 2 for Monday and so on). Then you could say if 1, add 2, if 2, add 2, etc. Basically doing the same thing as your calculated formula, but with workflow actions.
At this point you should have a couple ways to accomplish whatever you’re trying to do with working days. I hope it was useful!
If you need assistance with or would like to discuss your HR New Hire Onboarding processes or any other SharePoint workflows, contact us!
This article was first published by C5insighyt.
