Calculate a Due Date Based on Business Hours With Nintex Workflow

More than a few times, I have come across the requirement to calculate a due date based on business hours. Recently I needed such a capability for a help desk application that had been built in Nintex Workflow. It’s not quite as simple as it sounds – it’s the business hours part of it that makes it relatively tricky. After a cursory search, while there were a few that would calculate based on days, I couldn’t find any solutions out there to suit this requirement, so I decided to build my own.

The help desk workflow looks up the type of issue from a list, retrieves the expected close time from a Service Level Agreement (SLA) field, and that is used to calculate the due date (along with alert times). SLAs are in business hours,  and the business is measure on overdue times, so it is important that this is accurate.

The workflow itself had been built originally with Nintex Workflow 2007, and a web service had been utilized that served this purpose, but that option was no longer available in the customer’s new SharePoint 2013 environment due to authentication issues. The good news is, Nintex Workflow 2013 contains a feature called User Defined Actions (UDAs) that would allow me to get the job done.

In a nutshell, a UDA allows a workflow developer to encapsulate a workflow, have it accept input parameters have it output results as parameters. Then, that UDA can be used in other workflows as required. It is essentially a workflow function. I was able to successfully build a UDA to do this, and I am providing it here:

Nintex UDA to calculate a due date based on business hours

The basic logic of the UDA goes something like this. Starting with a date, a number of days, hours and minutes, it first calculates the number of minutes that the issue is to be open. The number of days is multiplied by the number of business hours in a day (retrieved from workflow constants), the hours by 60, and these are added to the minutes parameter.

Next, we test to see if it is a business day (determined from a list of holidays and whether the day is a Saturday or Sunday). Next, we see if the date is today, and if we are within business hours. If so, we subtract the remaining minutes in the business day from the minutes outstanding. We then increment the day, and repeat the loop until there are more minutes in the current date than are outstanding. Once that happens, we add the outstanding minutes to the current date, and output is as the due date/time.

The package above contains two files – the UDA itself, and a list template. In order to get the UDA working, you first need to create the Holidays list, and two Nintex Workflow constants. The package contains a list template, Holidays.stp. I’m going to assume that adding a list template to the list template gallery is a well known procedure, and not step through it here, but it needs to be done. Once added, create a new list using the Holidays template, and pops appropriate. It comes with 3 annual holidays already defined, Christmas, Boxing Day, and New Years Day. If the holiday falls on the same date every year, it only needs to be added once, and the “Annual” option checked (the year can be ignored). Otherwise, each holiday must be explicitly added.

Next, two workflow constants need to be created – WorkdayEnd and WorkdayStart. They will use the Number type and represent the number of minutes from midnight that the work day starts and ends. 8:00 AM is 8×60 minutes from midnight and therefore the value is 480.

image

image

We then need to import our UDA. To do so, go to Settings – Nintex Workflow – Manage User Actions.

image

Next import the UDA from the file extracted from the package above (Calculate_Due_Date.uda). Once imported, it will likely be necessary to edit a couple of the UDA actions to connect them to the list and constants. These actions are easy to identify as they will display a yellow alert flag.

image

You will not be able to publish the UDA until all of these connections are made.

Once published, you can use the UDA in your workflows. To do so, open the User Defined Actions section in your Nintex Workflow Designer, and drag the “Calculate Due Date” action onto the workflow design surface. Next, configure the action.

image

Supply a starting date/time, the number of days, hours, and minutes to leave it open, and then assign the Due Date parameter to your workflow variable. That’s all there is to it.

There is nothing compiled in the UDA, and you can modify it to meet your needs. Hopefully this helps out a few people looking for this capability.

16 thoughts on “Calculate a Due Date Based on Business Hours With Nintex Workflow”

  1. Any chance we can get a 2010 version? Or at least some screen shots of the UDA and List so I can reproduce it more easily ? Thanks

  2. Nevermind I was able to convert the UDA by changing the .uda to .zip, extracting the XOML file and replacing all Version=15.0.0.0 with Version 14.0.0.0 and then re-zipping and changing back to a .uda

    Thanks for this UDA it saved me a lot of time not having to do it from scratch!

  3. When you configure the Query List action, what fields should we be outputting to HolidayResult?

  4. Hi John,

    Have you noticed this UDA breaks if you try to add business hours to a DateTime that occurs before business hours? I’ve been trying like hell to get it working no matter what time you start the operation to no avail. I even completely rewrote it so that I could better understand your process.

    Can you help me out a bit?

  5. Hi John,
    thanks for your share, I’ve imported the UDA and Iìve found the 2 query list actions to insert the “Holidays” list but I which is the output field to insert?

    Then, you mention the need to link the two workflow constants can you explain you how?

    Thanks again.

  6. Ok, not sure why or if I’m missing something very obvious but I cant see the query lists? It will not let me publish without editing them but were are they?

  7. Hi John, is there any help you can provide on what to filter on the holidays list and what the connecting outputs should be for both the query list actions? I assume you filter on day=txtCurrentDayOfMonth, and Month=txtCurrentMonth, and Year=txtCurrentYear to establish if there is a holiday match but what field do you output to and what is the second query configuration settings based on HolidayResult being empty. Apologies if I’m missing something obvious here:)

  8. To answer the question above as to “cant see the query lists” – you need to maximize the holiday check action set

  9. Struggling with configuration of the 2 Query Lists under the Holiday Check can anyone advise? Thanks.

  10. I’m in the same boat as others. Need to know what is being passed in the 2 query list actions in the UDA. Tried to edit the xoml directly but not able to add it in as a UDA. HELP!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.