Receive error when trying to populate date picker by code

G

Greg Collins [InfoPath MVP]

Your date field is allowed to have no value. This means that in the XML it has an attribute on it (xsi:nil="true"). This attribute tells InfoPath that it is okay for this non-string data-type field (i.e. a date-type field) is allowed to have no value. Normally non-string fields cannot be blank. Thus this attribute.

You need to, in code, first remove the xsi:nil attribute (if present) and then set your field value, because the two cannot be present at the same time: either it is NIL or it has a value -- not both.

Then if you ever set your field back to blank, you must add the xsi:nil attribute back to the node, or you'll get an error in the form stating that it is a required field and cannot be blank.
 
J

Jamz68

Thanks Greg for your assistance. I tried what you suggested. It did allow me
to set the date without first having the field populated, however it broke
the control. It only displays the date now instead of date and time. I
managed a workaround however. Using a rule, I set the value of the second
date picker from the first then I was able to adjust the start and ending
time for the appointment with code by parsing the field contents and saving
it back into the field after changing it.
 
G

Greg Collins [InfoPath MVP]

Removing xsi:nil is mandatory if you want to set a value. It does not "break" the control--in fact it does not effect the control, just the data node in the XML.

Double check that your control is set to show both date and time, and then double check that the value you are setting via code is in the correct XML data/time format:

yyyy-MM-ddTHH:mm:ss
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top