Page 1 of 1

Empty date fields in MVC & how to handle them

Posted: April 1st, 2022, 4:20 pm
by tzdanows
Hi, so I just wanted to write about this because it was a bit interesting for me when I was working through it.

So if you have a date calendar field in the UI/view and you leave it empty, it will stay a BLANK and go through the flow of that view field. However, for my implementation in my filters controller which passes those controller parameters(the dates); I had a toJDEDate conversion that would convert it and pass it to the sub method. This would be able to compare that date in JDE format with my dates queried from JDE in the where clause of the inquire.

But here was the issue, the toJDEDate conversion takes BLANK and will set it to today's date by design. So I was unaware originally what was happening to my application and eventually found that interaction. So I just wanted to share the workaround I received from consulting with Jeremy and Cathy during our daily meetings and put it out there. If you happen to find a more intuitive solution, I would love to hear about it!

This was my favorite approach because it was the quickest to implement and most intuitive in my opinion:

This is for a date range so I would take in the first(from) and second(to) dates and convert them to JDE dates. Then within the controller I would pass it down as a parameter but rather than just selecting it. We can use an XSL Choose (courtesy of Jeremy). This would check if the original input was blank, then to keep it blank.(not convert it, converting causes issues) and else we would return the converted value.

Image

My original approach was also fun and was using binary decisions. Believe it or not, this approach was also valuable because it helped me debug my original issue with the approach above. Props to Cathy for helping to debug with that. The same XSL choose logic is implemented here but in the form of a binary decision. If the date was empty, we would avoid conversion. Else, convert the value and eventually the controller will pass the value we care for down to the submethod.

Image

Also I don't have access to platform5 currently to take a screenshot but my xsl choose looked like this in approach #1 for each date parameter passed down to the submethod.

Code: Select all

<xsl:choose>
	<xsl:when test="WorkData/_ControllerParameters/fromdate = ''"></xsl:when>
	<xsl:otherwise>
		/.../JDEConversionService/fromdate... (this will be returned, I don't know the path off the top of my head
	</xsl:otherwise>
</xsl:choose>
So, what did I learn from this? That I need to use services to replicate tests when I'm lost because approach #1 was the efficient approach but approach #2 helped me sort out what was going wrong for figuring out what that empty field was passing and ensuring I was checking the right values. I'd love to hear about other implementations similar to this. Also the logic for the binary decision one was too fun!

Thanks and have a good weekend!