Solved

How can I default a date field to the next Monday date?

  • 15 November 2017
  • 8 replies
  • 63 views

In SharePoint, the field is already configured as a calculated date with this formula: =Today+6-WEEKDAY(Today+4)

That works in the standard edit mode when adding a item, but that does not work in Nintex (Expression)

icon

Best answer by lakshminarayana 16 November 2017, 06:46

View original

8 replies

Badge +9

You can use following JavaScript to set a date control default to Next Monday.

NWF$(document).ready(function()
{
var d = new Date();
var twoDigitMonth = ("0" + (d.getMonth() + 1)).slice(-2);
var currentDate = (d.getDate() + (1 + 7 - d.getDay()) % 7) + "/" + twoDigitMonth + "/" + d.getFullYear();
NWF$('#' + fldDateClosed).val(currentDate);
});

Thank you Lakshmi!

Can you tell me where/how I insert the JavaScript in the date control ?

The control is currently connected to a date column for a list in SharePoint.

In Nintex, I right-click on Settings. Then in Control Settings - Date/Time dialog, I can't find a place to insert the JavaScript other than the Expression in the Advanced section.

I'm very new to Nintex, so I appreciate your help.

Regards!

Badge +9

Go to the form settings to input the custom JS

After that open the control settings of the date control and add the js variable

Is that date formatted correctly for you?

That worked perfectly, thank you!

Hi Chadd,

Is it possible to change the date format to mm-dd-yyyy  ? It is currently set to dd-mm-yyyy but the system is set to mm-dd-yyyy, so it is showing wrong values in the calculated date field.

I tried using the fn-FormatDate function but doesn't work for me.

Thanks for your help.

Justo

Badge +9

Hey Justo,

The format of the date is dependent on the JavaScript.

I'm not totally sure, I'd have to play around with it, but switching the twoDigitMonth and.getDay variable around might fix it.

(You may have to paste this in Notepad first, then copy it)

NWF$(document).ready(function()
{
 var d = new Date();
 var twoDigitMonth = ("0" + (d.getMonth() + 1)).slice(-2);
 var currentDate = twoDigitMonth + "/" + (d.getDate() + (1 + 7 - d.getDay()) % 7) + "/" + d.getFullYear();
 NWF$('#' + fldDateClosed).val(currentDate);
});

Give it a try, if it doesn't work, I can try to recreate the scenario in my environment. Let me know.

-Chadd

That did not work...

Thanks!

Badge +9

That's weird. I just tried it and it worked for me.

Reply