Calculated column formula to calculated value


Badge +3

I know that calculated columns don't work on Nintex forms. So my question is, how would I get the following calculated column formula converted into a calculated value on a form?

Calculated column formula: 

=TODAY()+(7-WEEKDAY(TODAY(),2))


10 replies

Userlevel 5
Badge +14

This should replicate what you're trying to achieve. 

formatDate(dateAddDays({Common:CurrentDate}, (7-(new Date ().getDay()))), "d")

Breaking it down into parts: 

//{Common:CurrentDate} === 3/7/2018

//new Date ().getDay() === 3 (aka: Wednesday)



formatDate(dateAddDays({Common:CurrentDate}, (7-(new Date ().getDay()))), "d");

// translated...

// formatDate(dateAddDays(3/7/2018 12:00AM, (7 - (3))), "d");

// translated...

// formatDate(dateAddDays(3/7/2018 12:00AM, 4), "d");

// translated...

// formatDate(3/11/2018 12:00AM, "d");

// translated...

// 3/11/2018
‍‍‍‍
Badge +3

For my understanding, what is "new Date" and ".getDay?" Where are these coming from? 

Userlevel 5
Badge +14

That's just basic javascript (JavaScript getDay() Method or Date.prototype.getDay() - JavaScript | MDN). 

Calculated Value control Formulas are just evaluating javascript at the end of the day, so you can use it inside of there with no problems (most of the time). 

Badge +3

I figured. However, not getting a result when I preview it, hence I asked. This is what I have: 

213723_pastedImage_1.png

Userlevel 5
Badge +14

Make sure that the view options in the properties of your calculated control are set to ReCalculate value on View:

213595_pastedImage_1.png


Otherwise you won't be able to preview it. 


Badge +3

Hmmmm. Mine seems to still be blank...

213724_pastedImage_1.png

Userlevel 5
Badge +14

Please copy and paste the code in my first reply into your formula field. You have a typo after the getDay where you have left off the invoking parentheses. 

Badge +3

My man! Perfect! Preciate it!!

Badge +3

nmarples‌ Do you know if there is a way to restrict a datepicker to not allow for future dates. I was trying to come up with an expression within the Date/Time control to do this, but I think its going to have to be done with javascript. 

With that said, I think I'm close. I know I can do the following or something similar: 

$('#datepicker').datepicker({ maxDate: 0 })

which would essentially not allow for any date past 'today.'

I'm having trouble converting this to being used on the form. I think I would need to store it in the javascript variable and reference it, but I'm not sure.

Badge +2

Hi,

sorry to hijack this thread but as I have an issue similar to this but have a formula on premise which works and want it to work in o365, I thought I'd add it.

It calculates from the current date the date of the previous friday:

=IF(WEEKDAY([Current Date])<6,[Current Date]-(11-WEEKDAY([Current Date])),[Current Date]+5-WEEKDAY([Current Date]))

However, I'm a bit stumped as to how to imp[lement it in the samesimilar way as to how you solved this one with your formula.

Any help would be much appreciated.

Regards

Julian

Reply