Page 1 of 1

SO Line Scheduled Date

PostPosted: Thu Sep 24, 2020 9:36 am
by pricerc
Customer asks: "Can we make it default to null?"

They would like to repurpose it as an expiry date.

Me: can't even change it to null - if I clear the editor, it defaults back to today's date as soon as I tab away. It seems the best I can do is make it something like 1/1/1900.

I can't find code that's changing ScheduledDate in any plugins.

Is this possible, or would we need to go down the custom field route?

Re: SO Line Scheduled Date  Topic is solved

PostPosted: Thu Sep 24, 2020 10:43 am
by Scott.Pearce
The SalesOrderLine.ScheduledDate property is a Date type. The Date type is a value-type and therefore cannot be set to NULL. Normally when dealing with the Date type, in programming circles, DateTime.MinValue is used to denote NULL or "no date". Sadly Jiwa does some silly things with the saving of SalesOrderLine.ScheduledDate when it is set to DateTime.MinValue (Jiwa saves NULL to the database) and with the reading of SalesOrderLine.ScheduledDate (if null then use Today). This behaviour thwarts my attempts to use the DateTime.MinValue-as-NULL technique.

HOWEVER, in a similar vein to the aforementioned strategy, I have instead leveraged DateTime.MaxValue and jumped through a hoop or two to achieve what you want. Best to look at the plugin for an understanding. In a nutshell, we are using a special known date value, and when we come across said value during display, we set the cell.Value to NULL, which gives a blank cell. Note that reports, etc. must be made intelligent enough to know about the special known date value in SO_Lines.ScheduledDate (in this case DateTime.MaxValue) and treat it accordingly.

Plugin SO Line Scheduled Date NULL by default.xml
(36.66 KiB) Downloaded 25 times

Re: SO Line Scheduled Date

PostPosted: Thu Sep 24, 2020 12:27 pm
by pricerc
Scott.Pearce wrote:The SalesOrderLine.ScheduledDate property is a Date type. The Date type is a value-type and therefore cannot be set to NULL. Normally when dealing with the Date type, in programming circles, DateTime.MinValue is used to denote NULL or "no date". Sadly Jiwa does some silly things with the saving of SalesOrderLine.ScheduledDate when it is set to DateTime.MinValue (Jiwa saves NULL to the database) and with the reading of SalesOrderLine.ScheduledDate (if null then use Today). This behaviour thwarts my attempts to use the DateTime.MinValue-as-NULL technique.

HOWEVER, in a similar vein to the aforementioned strategy, I have instead leveraged DateTime.MaxValue and jumped through a hoop or two to achieve what you want. Best to look at the plugin for an understanding. In a nutshell, we are using a special known date value, and when we come across said value during display, we set the cell.Value to NULL, which gives a blank cell. Note that reports, etc. must be made intelligent enough to know about the special known date value in SO_Lines.ScheduledDate (in this case DateTime.MaxValue) and treat it accordingly.

Plugin SO Line Scheduled Date NULL by default.xml



Thanks Scott, I'll take a look.

I know it's a date type, but I also noticed that the field in SQL is nullable, and that there is logic in Jiwa that maps NULL SQL dates to datetime.minvalue, so I was kinda hoping there was something I'd missed.

Re: SO Line Scheduled Date

PostPosted: Thu Sep 24, 2020 12:31 pm
by Scott.Pearce
and that there is logic in Jiwa that maps NULL SQL dates to datetime.minvalue


Yep, and if only we mapped back the other way when we read the line! When reading a line we initialise ScheduledDate to Today(), and then only set it if the database value is NOT NULL. The net effect being that NULL values get read in as the current date. :-(