Skip to main content

Nintex form business days calculator

 function doCalc()

{

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

}

Comments

Popular posts from this blog

Event Date Function

  Date.toISOFormat = function (date, ignoreTime) {      /// <summary>Date object static method to format a date to date ISO string - YYYY-MM-DDThh:mm:ssZ</summary>      /// <param name="date" type="Date" mayBeNull="false" optional="false"></param>      /// <param name="ignoreTime" type="Boolean" mayBeNull="false" optional="true"></param>      /// <returns type="String">A string representing ISO format for specied date</returns>        // If not specified, time is ignored      var ignoreTime = ignoreTime || {};        function pad(number) {          // Add leading 0 if number is less then 10 (enclosed method)          var r = String(number);          if (r.length ==...

The _spPageContextInfo

I f you are creating a SharePoint app using JavaScript and the Client side object model you need this friendly object. In the development of an app, you would require some basic properties- SharePoint as a framework provides these with the  _spPageContextInfo  object. _  spPageContextInfo  will provide these below properties:  webServerRelativeUrl  webAbsoluteUrl siteAbsoluteUrl serverRequestPath layoutsUrl webTitle webTemplate tenantAppVersion isAppWeb webLogoUrl webLanguage currentLanguage currentUICultureName currentCultureName env nid fid clientServerTimeDelta updateFormDigestPageLoaded siteClientTag crossDomainPhotosEnabled webUIVersion webPermMasks pagePersonalizationScope userId userLoginName systemUserKey alertsEnabled siteServerRelativeUrl allowSilverlightPrompt themedCssFolderUrl themedImageFileNames

PublishingAssociatedContentType

The Content Type to be associated with a page layout is indicated by the 'PublishingAssociatedContentType'. In the actual sense it means a binding setting between the Page Layout and the content type. If you fail to provide one, the SharePoint framework will make use of the Page Content type. The format of the binding is: ';# e.g. ';#ContentPage;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900470b13dd348649d08f9e5151501df9a4000dbd46dad8d045f98c83ad983b66d3f2;#'. where Content Type name: ContentPage Content Type ID: 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900470b13dd348649d08f9e5151501df9a4000dbd46dad8d045f98c83ad983b66d3f2 respectively. QED