0

I need to assign a calculated value to date field in infopath form. I am unable to assign the value as I get "schema validation found non- datatype errors" error. The following is my code:

    int periodOfWarranty = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:SecWarrantyDetails/my:txtPeriodofWarranty", NamespaceManager).ValueAsInt;
    DateTime startDate = (MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:SecWarrantyDetails/my:dpWarrantyStartDate", NamespaceManager).ValueAsDateTime).Date;
    DateTime endDate = startDate.AddYears(periodOfWarranty).Date;
    MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:SecWarrantyDetails/my:dpWarrantyEndDate", NamespaceManager).SetValue(endDate.ToString("d"));

Please guide me regarding the error in my code.

0

Mancy,

Following should help:

XPathNavigator endDateNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:SecWarrantyDetails/my:dpWarrantyEndDate", NamespaceManager);

if (endDateNode.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
   endDateNode.DeleteSelf();

endDateNode.SetValue(endDate.ToString("yyyy-MM-dd"));

InfoPath Date control do not accept any other format than "yyyy-MM-dd", also sometime it give the validation error because of nil attribute.. So removing the nil attribute before setting value..

Source:
http://www.infopathdev.com/forums/t/9400.aspx

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.