I have a form that has to auto fill fields, Date and RFQ ( which is a number built from the current date and time ). On the creation of a new form, these both work perfectly. My problem is after a form has been filled and saved to Share Point, when it is re-opened, the feilds are updated to the current date and time again, which I do not want. I have written a couple of Javascript IF statements that check to see if the fields are empty before filling with the current D&T, and the code works perfectly when placed in an OnClick event. But when I move the code to the OnLoad event, the fields are updated whether it's a new form or one that already contains data. I think the form is running the script before the fields can be updated with the data. Is there a way to use a Javascript delay with the Infopath OnLoad function, or is there something else I could be doing? Any help would be very appreciated. Below is my code for the Date field (the other is too long to post, and if I can get this one to work, they should both work anyway).
function XDocument::OnLoad(eventObj)
{
// Write your code here
if (XDocument.DOM.selectSingleNode("/my:myFields/my:header/my:Date").text != " ")
{
var ldate = new Date();
XDocument.DOM.selectSingleNode("/my:myFields/my:header/my:Date").text = ldate.toLocaleDateString();
}
}
Thanks Again,