Skip to main content

I am using a smart object to persist some values to the smart box.  I have a few date time fields that, when set to a null value, fail with a 'string cannot be converted to a date' error.  I am creating the smart object through a smart object event, so I don't really have the ability to put an 'If not null then set value' condition for the dates.


Why aren't null date values allowed when creating smart box smart objects?  I could just turn the date fields to be of data type 'text' to get around the problem, but that might make reporting more tedious later.  Any thoughts?

Are your datetime fields also set as keys, by chance?


Are you sure you're passing in a null value, or could it also possibly be a String.Empty ?


Is it possible in your application that you can use the MinDate() value or something similar, if you absolutely had to?


are you creating your datetime column through infopath or c#?


If you are doing this in infopath, i'm sure there's a way to validate it. In C# it would be a doddle.


Martni


The datetime fields are not key values, and I am fairly certain that I am pasing a null and not string.empty.  I have confirmed with K2 that this is expected behavior and that I will need to use a special date to represent null (MinDate, probably).  Thanks for your input!
The date fields were being populated in InfoPath, but I legitimately want them to be null which is something the smart objects just can't handle.  I'll just start switching nulls to mindate on save, and mindate back to null on load I guess.

I've experience strange behaviors with nulls lately myself. One technique I am employing is to check the fields for null before assignment, and if they are null not assigning it at all. I have a SmartObject right now with a lot of 'scnull' values in the string columns, which in my opinion is pretty strange behavior in its own right...


By default DateTime is not nullable because it is a Value Type, using the nullable operator introduced in C# 2, you can achieve this. Using a question mark (?) after the type or using the generic style

 

Nullable. Nullable < DateTime > nullDateTime;

 

or

 

DateTime? nullDateTime = null;

 

More about.....Nullable DateTime

 

Nick


Reply