{"id":704,"date":"2021-08-30T18:15:32","date_gmt":"2021-08-30T22:15:32","guid":{"rendered":"http:\/\/www.markwheeler.com\/?p=704"},"modified":"2021-08-30T18:15:32","modified_gmt":"2021-08-30T22:15:32","slug":"calculating-business-days-for-nintex-form","status":"publish","type":"post","link":"https:\/\/www.markwheeler.com\/?p=704","title":{"rendered":"Calculating Business Days for Nintex Form"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Had a request to calculate several deadline or due dates from one specific date to autopopulate fields on a Nintex form. This also had to calculate business days only excluding holidays and weekends. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I am using the <a href=\"https:\/\/momentjs.com\/\" data-type=\"URL\" data-id=\"https:\/\/momentjs.com\/\">moment.js library<\/a> and <a href=\"https:\/\/www.npmjs.com\/package\/moment-business-days\">moment-business-days<\/a> plugin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Upload those .js files to your site assets folder and add the full URL to the Custom Javascript includes on your form Settings.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"615\" height=\"132\" src=\"http:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/image-2.png\" alt=\"\" class=\"wp-image-711\" srcset=\"https:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/image-2.png 615w, https:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/image-2-300x64.png 300w\" sizes=\"auto, (max-width: 615px) 100vw, 615px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure to add Client ID JavaScript variable names to your date fields.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"659\" height=\"65\" src=\"http:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/image.png\" alt=\"\" class=\"wp-image-707\" srcset=\"https:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/image.png 659w, https:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/image-300x30.png 300w\" sizes=\"auto, (max-width: 659px) 100vw, 659px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>NWF.FormFiller.Events.RegisterAfterReady(function () {\n    var tday = '11-25-2021'; \/\/ These lines add holiday dates. \n    var xday = '12-24-2021'; \/\/ Moment.js calculations will exclude these days.\n    moment.updateLocale('us', {\n        holidays: &#91;tday, xday],\n        holidayFormat: 'MM-DD-YYYY'\n    });\n \nNWF$('#' + pUp).change(function () { \/\/ Execute when my master deadline date changes. Update other date fields.\n\n\/\/ Calculate Add\/Subtract by Calendar days \n\/\/ var newDate =  moment(NWF$('#' + pUp).val(), 'MM\/DD\/YYYY').add('days', 7);\n\/\/ var newDate =  moment(NWF$('#' + pUp).val(), 'MM\/DD\/YYYY').subtract('days', 7);\n\/\/ var newrd = moment(newDate).format('MM\/DD\/YYYY');\n\/\/ NWF$('#' + rework).val(newrd);\n\/\/ NWF$('#' + rework).change();\n\n\/\/ Calculate Add\/Subtract by Business days\t\t\t\nvar newdate = moment(NWF$('#' + pUp).val(), 'MM\/DD\/YYYY').businessAdd(7)._d;\n\/\/ var newdate = moment(NWF$('#' + pUp).val(), 'MM\/DD\/YYYY').businessSubtract(7)._d;\nvar newrd = moment(newdate).format('MM\/DD\/YYYY');\nNWF$('#' + rework).val(newrd);\nNWF$('#' + rework).change();\n});\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In my specific scenario, I am back-populating or subtracting business\/holiday days based on a master due date (highlighted).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"362\" height=\"205\" src=\"http:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/image-1.png\" alt=\"\" class=\"wp-image-709\" srcset=\"https:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/image-1.png 362w, https:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/image-1-300x170.png 300w\" sizes=\"auto, (max-width: 362px) 100vw, 362px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Had a request to calculate several deadline or due dates from one specific date to autopopulate fields on a Nintex form. This also had to calculate business days only excluding holidays and weekends. I am using the moment.js library and moment-business-days plugin. Upload those .js files to your site assets [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":715,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[10,11],"tags":[72,98],"class_list":["post-704","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sharepoint","category-software","tag-nintex","tag-sharepoint"],"jetpack_featured_media_url":"https:\/\/www.markwheeler.com\/wp-content\/uploads\/2021\/08\/moment.png","_links":{"self":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=704"}],"version-history":[{"count":0,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/704\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/media\/715"}],"wp:attachment":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}