Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

DataDOM.OnBeforeChange Event

Office 2007
Occurs after changes to a form's underlying XML document have been made but before the changes are accepted.

Version Information
 Version Added:  InfoPath 2003

Syntax

expression.OnBeforeChange(pDataDOMEvent)

expression   An expression that returns a DataDOM object.

Parameters

NameRequired/OptionalData TypeDescription
pDataDOMEventRequiredDataDOMEventAn event object that is used during Microsoft Office InfoPath 2007 data validation events.

Return Value
nothing

Remarks

This event handler allows users to cancel an operation.

During the OnBeforeChange event, the form's underlying XML document is placed in read-only mode. If the ReturnStatus property of the DataDOMEvent object is set to False, Office InfoPath 2007rejects the changes that were made and a message box is displayed to the user. If an error occurs in the scripting code for the OnBeforeChange event handler, InfoPath rejects the changes and restores the data to its previous state.

Bb229734.vs_note(en-us,office.12).gif  Notes
  • It is best to avoid switching views during the OnBeforeChange event; changes have not yet been accepted, and switching to another view may result in an error.
  • In some cases, events related to changes in a form's underlying XML document may occur more than once. For example, when existing data is changed, an insert and delete operation occurs.
  • If a validation error is encountered in any OnBeforeChange event handler, the document fails to load. A
    JScript
    try-catch
    block in the OnLoad event can be used to catch this validation failure and to load the document despite the error.

Example

In the following example, the OnBeforeChange event handler is used to validate the data in a field. If the data is not valid, the ReturnStatus property of the DataDOMEvent object is used to reject the changes.

JScript
function msoxd__RepVisitDt::OnBeforeChange eventObj)
{
   var oNode = XDocument.DOM.selectSingleNode
      ("/Customers/CustomerInfo/ContactDates/PhoneContactDt");

   if (!oNode.text)
   {
      eventObj.ReturnMessage = "The Phone Contact Start date must be 
         set prior to the Representative Visit date.";
      eventObj.ReturnStatus = false;
      return;
   }

   // If the data is valid, eventObj.ReturnStatus = true.
   eventObj.ReturnStatus = true;
   return;
}



Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.