File: inconFormEventsInEVTForm.htm

package info (click to toggle)
office2003-schemas 1.0%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, forky, sid, trixie
  • size: 42,304 kB
  • sloc: javascript: 2,429; makefile: 29
file content (84 lines) | stat: -rw-r--r-- 14,419 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<html dir="ltr"><head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="assetid" CONTENT="HV01027388"><META NAME="lcid" CONTENT="1033"><title>Form events in the Events developer sample form</title><link rel="stylesheet" type="text/css" href="office10.css"><script type="text/javascript" language="Javascript" src="ExpCollapse.js"></script><script type="text/javascript" language="JavaScript" src="inline.js"></script></head><body><p id="ExpandAllLine" class="ExpFav"><a href="#" onclick="ExpandAll()" onkeypress="ExpandAll()" class="DropDown"><img id="picHeader" border="0" src="expandtri.gif" alt="Show All"><span id="ExpandAll">Show All</span></a></p><h1>Form events in the Events developer sample form</h1><div class="ofvbanav"><span class="ofvbanavreuse" id="seealso" onclick="toggleList()" onkeypress="toggleList()"></span><span class="ofvbanavreuse" id="specifics" onclick="toggleList()" onkeypress="toggleList()"></span></div><p>The Events developer sample form implements a variety of Microsoft Office InfoPath 2003 form events that can be used to respond to specific activities that occur when a form is opened and while it is being filled out. Form events can occur when a form's version number is validated, when a form is opened, when a form view is changed, and after a form has been merged with another form.</p><p>The following table lists each of the form events implemented in the Events developer sample form, along with a description of how they are used.</p><table><tr><th>Event</th><th>Description</th></tr><tr><td><b class="bterm"><a href="xdevtOnVersionUpgrade.htm" id="HV01021373" lcid=" ">OnVersionUpgrade</a></b>
				</td><td>Used to verify that the version number of the form being opened matches the version number of the form when it was originally designed. If the version numbers do not match, this event occurs and scripting code can be used to update the form or display an error message.</td></tr><tr><td><b class="bterm"><a href="xdevtOnLoad.htm" id="HV01021369" lcid=" ">OnLoad</a></b>
				</td><td>Used to initialize the form as it is being opened. When this event occurs, scripting code can be used to set the appropriate view based on data contained in the form.</td></tr><tr><td><b class="bterm"><a href="xdevtOnSwitchView.htm" id="HV01021371" lcid=" ">OnSwitchView</a></b>
				</td><td>Used when changing from one view to another. This event occurs when a user changes views, and scripting code can be used to insert data into the form.</td></tr><tr><td><b class="bterm"><a href="xdevtOnAfterImport.htm" id="HV01021367" lcid=" ">OnAfterImport</a></b>
				</td><td>Used to provide additional processing after a form has been merged with another form. This event occurs after data is imported from another form, and scripting code can be used to set the appropriate view based on the merged data contained in the form.</td></tr></table><p><b>Note</b>  The <b class="bterm"><a href="xdevtOnSubmitRequest.htm" id="HV01021370" lcid=" ">OnSubmitRequest</a></b> event is also a form event, but it was not used in the Events developer sample form.</p><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using the OnVersionUpgrade event</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">OnVersionUpgrade</b> event occurs when a form is opened that contains a version number that is older than the version number of the form when it was originally designed. The version number of a form is contained in the <b class="bterm"><a href="xsfatrsolutionVersion.htm" id="HV01021608" lcid=" ">solutionVersion</a></b> attribute of the form's <b class="bterm">mso-infoPathSolution</b>
					<a href="#" class="glossary" onclick="AppendPopup(this,'xdprocessinginstructions')" onkeypress="AppendPopup(this,'xdprocessinginstructions')"> processing instruction</a>.</p><p>To use the <b class="bterm">OnVersionUpgrade</b> event, you use the <b class="ui">Advanced</b> tab of the <b class="ui">Forms Options</b> dialog box, which is available on the <b class="ui">Tools</b> menu in <a href="#" class="glossary" onclick="AppendPopup(this,'xddesignmode')" onkeypress="AppendPopup(this,'xddesignmode')">design mode</a>.  This tab
					allows you to set the version number of the form and specify how you want InfoPath to handle version upgrades. To enable the <b class="bterm">OnVersionUpgrade</b> event, select
					<b class="ui">Use script event</b> in the <b class="ui">On version upgrade</b>
					box, and then click
					<b class="ui">Edit</b>. This opens
					<a href="#" class="glossary" onclick="AppendPopup(this,'xdmicrosoftscripteditormse')" onkeypress="AppendPopup(this,'xdmicrosoftscripteditormse')">Microsoft Script Editor (MSE)</a> and displays the InfoPath-generated <a href="#" class="glossary" onclick="AppendPopup(this,'xdeventhandler')" onkeypress="AppendPopup(this,'xdeventhandler')">event handler</a>.</p><p><b>Note</b>  Event handlers in InfoPath must be created in design mode.</p><p>In the Events developer sample form, the <b class="bterm">OnVersionUpgrade</b> event is determines
					whether the form with the incorrect version number contains an EmailAddress element. If it does
					not, one is added. If the operation is not successful, the <b class="bterm"><a href="xdmthAlert.htm" id="HV01021376" lcid=" ">Alert</a></b> method of the <b class="bterm"><a href="xdobjUI.htm" id="HV01021247" lcid=" ">UI</a></b> object is used to notify the user. The following example from the Events developer sample form shows the <b class="bterm">OnVersionUpgrade</b> event handler:</p><pre><code>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 &lt;item&gt; element to the XML document as a 
         // child of the &lt;order&gt; element.
         XDocument.DOM.selectSingleNode("/Customers/CustomerInfo")
            .appendChild(objItemNode);
      }
      catch(ex)
      {
         XDocument.UI.Alert("There was an error inserting the " +
           "&lt;EmailAddress&gt; node.\nDescription: " + ex.description);
      }
   }
}</code></pre><p>To test the <b class="bterm">OnVersionUpgrade</b> event, open the Events developer sample form, click <b class="ui">Open</b> on the <b class="ui">File</b> menu, and  open the WRONGVER.XML file located in the SAMPLES folder. This form contains a version number that is older than the original Events developer sample form, and it does not contain an EmailAddress element. When you save the form after InfoPath has corrected it using the scripting code contained in the <b class="bterm">OnVersionUpgrade</b> event, the version number and EmailAddress element are updated.</p></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using the OnLoad event</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">OnLoad</b> event occurs when an InfoPath form is opened (or loaded).</p><p>To use the <b class="bterm">OnLoad</b> event, you click
					<b class="ui">On Load Event</b>
					on the <b class="ui">Script</b> submenu located on the <b class="ui">Tools</b> menu in <a href="#" class="glossary" onclick="AppendPopup(this,'xddesignmode')" onkeypress="AppendPopup(this,'xddesignmode')">design mode</a>. This opens
					<a href="#" class="glossary" onclick="AppendPopup(this,'xdmicrosoftscripteditormse')" onkeypress="AppendPopup(this,'xdmicrosoftscripteditormse')">Microsoft Script Editor (MSE)</a> and displays the InfoPath-generated <a href="#" class="glossary" onclick="AppendPopup(this,'xdeventhandler')" onkeypress="AppendPopup(this,'xdeventhandler')">event handler</a>.</p><p><b>Note</b>  Event handlers in InfoPath must be created in design mode.</p><p>In the Events developer sample form, the <b class="bterm">OnLoad</b> event checks the form's underlying XML document for the existence of certain data. Based on the values that are found, the <b class="bterm">OnLoad</b> event then sets the appropriate view using the <b class="bterm"><a href="xdproIsDefault.htm" id="HV01021287" lcid=" ">IsDefault</a></b> property of the <b class="bterm"><a href="xdcolViewInfos.htm" id="HV01021188" lcid=" ">ViewInfos</a></b> collection, which is accessed through the <b class="bterm"><a href="xdobjXDocument.htm" id="HV01021254" lcid=" ">XDocument</a></b> object. The following example from the Events developer sample form shows the
					<b class="bterm">OnLoad</b> event handler:</p><pre><code>function XDocument::OnLoad(eventObj)
{
   oContactedNode = XDocument.DOM
      .selectSingleNode("/Customers/CustomerInfo/Contacted");
   oArchivedNode = XDocument.DOM
      .selectSingleNode("/Customers/CustomerInfo/Archived");
   oCustomerName = XDocument.DOM
      .selectSingleNode("/Customers/CustomerInfo/CustomerName");

   if (oContactedNode.text == "false" &amp;&amp; !oCustomerName.text)
      XDocument.ViewInfos("New Customer").IsDefault = true;
   else if (oContactedNode.text == "false" &amp;&amp; oCustomerName.text)
      XDocument.ViewInfos("Contact Customer").IsDefault = true;
   else
      XDocument.ViewInfos("Archive Customer").IsDefault = true;
}</code></pre></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using the OnSwitchView event</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">OnSwitchView</b> event occurs when a user changes views in an InfoPath form. </p><p>To use the <b class="bterm">OnSwitchView</b> event, you click
					<b class="ui">On Switch Views Event</b>
					on the <b class="ui">Script</b> submenu located on the <b class="ui">Tools</b> menu in <a href="#" class="glossary" onclick="AppendPopup(this,'xddesignmode')" onkeypress="AppendPopup(this,'xddesignmode')">design mode</a>. This opens
					<a href="#" class="glossary" onclick="AppendPopup(this,'xdmicrosoftscripteditormse')" onkeypress="AppendPopup(this,'xdmicrosoftscripteditormse')">Microsoft Script Editor (MSE)</a> and displays the InfoPath-generated <a href="#" class="glossary" onclick="AppendPopup(this,'xdeventhandler')" onkeypress="AppendPopup(this,'xdeventhandler')">event handler</a>.</p><p><b>Note</b>  Event handlers in InfoPath must be created in design mode.</p><p>In the Events developer sample form, the <b class="bterm">OnSwitchView</b> event adds a note to the Archived Customer Notes field each time the Archived Customer view is selected. This is accomplished by using the <b class="bterm">selectSingleNode</b> method of the XML DOM, which is accessed through the <b class="bterm"><a href="xdproDOM_2.htm" id="HV01032776" lcid=" ">DOM</a></b> property of the <b class="bterm"><a href="xdobjXDocument.htm" id="HV01021254" lcid=" ">XDocument</a></b> object. The following example from the Events developer sample form shows the <b class="bterm">OnSwitchView</b> event handler:</p><pre><code>function XDocument::OnSwitchView(eventObj)
{

   var oDate = new Date();

   if (XDocument.View.Name == "Archive Customer")
   {
      var oNotesNode = XDocument.DOM
         .selectSingleNode("/Customers/CustomerInfo/Notes");
      var oDivNode = XDocument.DOM
         .createNode(1, "div", "http://www.w3.org/1999/xhtml");

      oDivNode.text = "Note recorded " + oDate.toString();
      oNotesNode.appendChild(oDivNode);
   }
}</code></pre></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using the OnAfterImport event</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">OnAfterImport</b> event occurs after a form has been merged with (or imported into) another form.</p><p>In the Events developer sample form, the <b class="bterm">OnAfterImport</b> event sets the appropriate view based on the data that the form contains after the merge is complete. This is accomplished by using the <b class="bterm"><a href="xdmthSwitchView.htm" id="HV01021422" lcid=" ">SwitchView</a></b> method of the <b class="bterm"><a href="xdobjView.htm" id="HV01021249" lcid=" ">View</a></b> object that is accessed through the <b class="bterm"><a href="xdobjXDocument.htm" id="HV01021254" lcid=" ">XDocument</a></b> object. The following example from the Events developer sample form shows the <b class="bterm">OnAfterImport</b>
					<a href="#" class="glossary" onclick="AppendPopup(this,'xdeventhandler')" onkeypress="AppendPopup(this,'xdeventhandler')"> event handler</a>:</p><pre><code>function XDocument::OnAfterImport(eventObj)
{
   XDocument.View.SwitchView("Archive Customer");
}</code></pre><p><b>Note</b>  The <b class="bterm">OnAfterImport</b> event is not available in <a href="#" class="glossary" onclick="AppendPopup(this,'xddesignmode')" onkeypress="AppendPopup(this,'xddesignmode')">design mode</a>. To use this event, you must manually create the event handler in the scripting file as shown in the preceding example.</p><p>To test the <b class="bterm">OnAfterImport</b> event, open the Events developer sample form, click <b class="ui">Merge Forms</b> on the <b class="ui">File</b> menu, and open the CUSTOMER.XML file located in the SAMPLES folder. This form contains customer contact information that can be merged with the Events developer sample form.</p></div><script type="text/javascript" language="JScript" src="ofvbanl.js"></script><span id="ofVBAISpan" class="ofvbaispan"><iframe id="ofVBAIFrame" frameborder="0" marginheight="0" marginwidth="4" scrolling="auto" width="100%" src="../links/inconFormEventsInEVTForm_l.htm"></iframe></span><center><a href="XMLSchemaCopyright_HV01147162.htm">&copy;2003-2004 Microsoft Corporation. All rights reserved.</a>  

Permission to copy, display and distribute this document is available at: <a 

href="http://r.office.microsoft.com/r/rlidAWSContentRedir?AssetID=XT010988631033&amp;CTT=11&amp;Origin=HV011232471033" 

target="_new">http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp</a></center></body></html>