cancel
Showing results for 
Search instead for 
Did you mean: 

Business Days Validation for Forms

Prevent a user from submitting a form, if the date selected in the form, is less than 30 business days from today.

AuthorVadim Tabakman
Long DescriptionNow at this stage, there's no business day calculations in Nintex Forms, so I had to be a little creative.  I thought I could use some JavaScript to do the validation but I didn't want to spend a whole bunch of time building it out from scratch.  Back when I was studying to be a development, they ingrained in us the concept of, don't reinvent the wheel.  So I went to Bing (yes I use that haha), and I found a function I could use : http://snipplr.com/view/4086/
Dependencies

None

Support InfoVadim Tabakman​ - Nintex Forms - Business Days Validation - Vadim Tabakman 
Compatibility

Nintex Forms 2010

Nintex Forms 2013

Platform

SharePoint Server 2010

SharePoint Server 2013

Screenshots

Video Link : 1171

Additional Information

Find out more or view other comments here Nintex Workflow - Terminate Previous Instances of a Workflow - Vadim Tabakman

function doWork()

{

  var myDate = NWF$('.cssDateChosen').find('input');

  var dFuture = new Date("December 31, 2015");

  dFuture = new Date(myDate.val());

  var dNow = new Date();

  var result = calcBusinessDays(getDateOnly(dNow),getDateOnly(dFuture));

  alert('Num of Business Day between Future date and now : ' + result + ' days');

}

function dateBusinessDayValidation(source, arguments)

{

  arguments.IsValid=true;

  var myDate = NWF$('.cssDateChosen').find('input');

  var dFuture = new Date(myDate.val());

  var dNow = new Date();

  var result = calcBusinessDays(getDateOnly(dNow),getDateOnly(dFuture));

  if(result < 30)

  {

    arguments.IsValid = false;

  }

}

function calcBusinessDays(dDate1, dDate2)

{

// input given as Date objects

var iWeeks, iDateDiff, iAdjust = 0;

if (dDate2 < dDate1)

  return -1; // error code if dates transposed

var iWeekday1 = dDate1.getDay(); // day of week

var iWeekday2 = dDate2.getDay(); iWeekday1 = (iWeekday1 == 0) ? 7 : iWeekday1; // change Sunday from 0 to 7

iWeekday2 = (iWeekday2 == 0) ? 7 : iWeekday2;

if ((iWeekday1 > 5) && (iWeekday2 > 5))

   iAdjust = 1; // adjustment if both days on weekend

iWeekday1 = (iWeekday1 > 5) ? 5 : iWeekday1; // only count weekdays

iWeekday2 = (iWeekday2 > 5) ? 5 : iWeekday2;  // calculate difference in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)

iWeeks = Math.floor((dDate2.getTime() - dDate1.getTime()) / 604800000) ;

if (iWeekday1 <= iWeekday2)

{

  iDateDiff = (iWeeks * 5) + (iWeekday2 - iWeekday1);

}

else

{

  iDateDiff = ((iWeeks + 1) * 5) - (iWeekday1 - iWeekday2);

iDateDiff -= iAdjust; // take into account both days on weekend

return (iDateDiff + 1); // add 1 because dates are inclusive

}

function getDateOnly(myDate)

{

  var dd = myDate.getDate();

  var mm = myDate.getMonth()+1;

  //January is 0!

  var yyyy = myDate.getFullYear();

  if(dd<10)

  {

      dd='0'+dd;

  }

if(mm<10)

{

   mm='0'+mm;

}

  var newDateOnly = mm+'/'+dd+'/'+yyyy;

  return new Date(newDateOnly);

}

Nintex Xchange Terms of Use Policy

Nintex makes no warranty or guarantee about the reliability, performance, quality, or functionality of any assets, and any assets you install are therefore provided as is. By downloading this asset, you agree to the terms of use.

Attachments
Version history
Revision #:
1 of 1
Last update:
‎05-20-2016 02:34 PM
Updated by: