XDocument.OnVersionUpgrade Event

InfoPath Developer Reference

Occurs when the version number of a Microsoft Office InfoPath 2007 form being opened is older than the version number of the form template on which it is based.

Version Information
 Version Added:  InfoPath 2003

Syntax

expression.OnVersionUpgrade(pEvent)

expression   An expression that returns a XDocument object.

Parameters

Name Required/Optional Data Type Description
pEvent Required VersionUpgradeEvent

Return Value
nothing

Remarks

This event handler allows users to cancel an operation.

During the OnVersionUpgrade event, the form's underlying XML document is placed in read-only mode, and it is not validated against the form's associated XML Schema. If the ReturnStatus property of the VersionUpgradeEvent object is set to False, InfoPath cancels the opening of the form. If an error occurs in the scripting code for the OnVersionUpgrade event handler, InfoPath ignores it and relies on the ReturnStatus property of the VersionUpgradeEvent object. If the ReturnStatus property is not explicitly set, the default value of True is used.

Example

In the following example, the OnVersionUpgrade event handler is used to determine whether the form with the incorrect older version number contains an EmailAddress element. If it does not, one is added.

JScript
  function XDocument::OnVersionUpgrade eventObj)
{
   if (!XDocument.DOM.selectSingleNode("/Customers/CustomerInfo/EmailAddress"))
   {
      try
      {
         // Create the new element.
         var objItemNode = XDocument.DOM.selectSingleNode("/Customers/CustomerInfo")
            .ownerDocument.createElement("EmailAddress");
     // Add the new <item> element to the XML document as a
     // child of the <order> element.
     XDocument.DOM.selectSingleNode("/Customers/CustomerInfo")
        .appendChild(objItemNode);
     eventObj.ReturnStatus=true;
  }
  catch(ex)
  {
     XDocument.UI.Alert("There was an error inserting the " +
        "<EmailAddress> node.\nDescription: " + ex.description);
     eventObj.ReturnStatus=false;
  }

} }

See Also