Skip to content

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 Comments

  1. Ryan Ryan

    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. Ryan Ryan

    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. Daniel Daniel

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

  4. Daniel Daniel

    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. Hey Daniel – I’ve never run into that issue. What’s breaking?

  6. Michele Michele

    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.

  7. Daniel Daniel

    Hey John,
    In my experience, passing your UDA a start time before the beginning of business hours causes the workflow to fail before it even starts.

    I tweaked the UDA, removing the Holidays check, changed the naming convention on the variables, restructured, fixed the before hours bug and a little more.

    Here’s my version
    https://www.dropbox.com/sh/thaoyz8hxk08mp1/AADXKO9TNobo4NP1owOq7qXqa?dl=0

  8. Sam Sam

    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?

  9. Same issue than Sam, can’t find the two query list…

  10. Noel Dickinson Noel Dickinson

    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:)

  11. Noel Dickinson Noel Dickinson

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

  12. SK SK

    What are the configurations of the query lists??

  13. SW SW

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

  14. Any update on the query lists? what to populate it with?

  15. Anonymous Anonymous

    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!

  16. I’m also struggling to work out what needs to be added into the 2 query list actions in the UDA. Help please!!

Leave a Reply

Your email address will not be published. Required fields are marked *

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