Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value of datetime field to null

Tags:

sharepoint

So, I´ve got an issue that someone might have solved (or so I hope). I have a datetime field that I use in a contenttype (on a listtemplate) that has its own editform.

Here´s a walkthrough of what happens:

  1. Adding a value to the datetime column and saving the updated value shows up (as expected).
  2. Updating the datetime column and adding null (emptying out the value) via the editform. The value isn´t updated but instead showing the old value.

I did some experimenting with this and I came to the conclusion that if I add an eventreceiver and try to update the value there it doesn´t even enter the eventreceiver as a blank string (I had an idea that the value is as a blank string and sharepoint can´t parse that to a null datetime) which leads me to think that there´s an issue with the fieldcontrol that causes this. I also found this article on MSDN which seems to be around the same issue. And also, the datetime field in the contenttype isn´t required.

Any ideas or suggestions?

UPDATE:

Apparently this only happens when I use a custom editform. When I use one of built in listtemplates this works like a charm.

like image 698
Johan Leino Avatar asked Nov 14 '22 15:11

Johan Leino


1 Answers

I've had similar issues with this in the past. It is indeed a known bug. One work around is to set the field to the min or max value of the type and check for this value wherever needed and do the appropriate conversions. Depending on your setup and use, you could create a trigger to convert min/max values to null and thus minimize the code required to handle such a work around.

like image 93
pdavis Avatar answered Feb 02 '23 06:02

pdavis