Infopath 2003 form - InfoPath Dev
in

InfoPath Dev

Infopath 2003 form

Last post 10-04-2011 08:21 AM by nsp_babu76. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 10-04-2011 08:21 AM

    Infopath 2003 form

    Hi,

    The IP form 2003 tries to send the form data as email without form attachment works fine in IP2003 client. When using IP2010 it sends the data along with the form attachment.

    In dataconnection added the submit to the email address and also checked the send only the active view option. Here is the .js

     

     /*
     * This file contains functions for data validation and form-level events.
     * Because the functions are referenced in the form definition (.xsf) file,
     * it is recommended that you do not modify the name of the function,
     * or the name and number of arguments.
     *
    */
     
    // The following line is created by Microsoft Office InfoPath to define the prefixes
    // for all the known namespaces in the main XML data file.
    // Any modification to the form files made outside of InfoPath
    // will not be automatically updated.
    //<namespacesDefinition>
    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-12-15T16:58:54" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
    //</namespacesDefinition>
     
    // Add the String trim function to the String prototype
    String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
     
    var ns = "/my:";   // The main namespace (ns) in the XML in this form
    var rootElement = "Test"; // The root element of the XML in this form
     
    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    //=======
    function XDocument::OnSubmitRequest(eventObj)
    {
     // Get this form's DOM object for later use
     var dom = eventObj.XDocument.DOM;
     
     // Define the beginning and ending delimiters for the IRMS email message.
     // Also, define the first line of the IRMS message body.
     var strB = ">>>";
     var strE = "<<<" + String.fromCharCode(10);
     var messageBody = "TestDI" + String.fromCharCode(10);
     
     // Get a reference to the data connection in this form entitled, "Submit".
     // This data connection is actually an EmailAdapter object, and it will be used
     // to send the IRMS email message (see Tools-->Data Connections...).
     var objEmailAdapter = XDocument.DataAdapters("Submit");
     
     var value;
     var i;
     var fields = new Array(26);
     var IFields  = new Array(26);
     
     // This array defines the field names on this form that hold the values to be sent to IRMS
     fields[0] = "hcpInfo" + ns + "salutation";
     fields[1] = "hcpInfo" + ns + "firstName";
     fields[2] = "hcpInfo" + ns + "lastName";
     fields[3] = "hcpInfo" + ns + "degree";
     fields[4] = ""; //placeholder for SpecCode - not sure what this field in IRMS is
     fields[5] = "hcpInfo" + ns + "title";
     fields[6] = "hcpInfo" + ns + "institutionName";
     fields[7] = "hcpInfo" + ns + "streetAddress";
     fields[8] = "hcpInfo" + ns + "city";
     fields[9] = "hcpInfo" + ns + "state";
     fields[10] = "hcpInfo" + ns + "zipCode";
     fields[11] = "hcpInfo" + ns + "phone";
     fields[12] = "hcpInfo" + ns + "fax";
     fields[13] = "hcpInfo" + ns + "email";
     fields[14] = "product";
     fields[15] = "responseMethod";
     fields[16] = "questions" + ns + "question1";
     fields[17] = "questions" + ns + "question2";
     fields[18] = "questions" + ns + "question3";
     fields[19] = "Test"; //placeholder for ReqBy
     fields[20] = "repInfo" + ns + "repName";
     fields[21] = "repInfo" + ns + "territoryNumber";
     fields[22] = "repInfo" + ns + "repPhone";
     fields[23] = "visitDate";
     fields[24] = "isInternationalReq";
     fields[25] = "venue";
     
     // This array defines the IRMS-specific field names that must be sent to IRMS
     IFields [0] = "Salutation";
     IFields [1] = "FirstName";
     IFields [2] = "LastName";
     IFields [3] = "Class";
     IFields [4] = "SpecCode";
     IFields [5] = "Title";
     IFields [6] = "Company";
     IFields [7] = "Address";
     IFields [8] = "City";
     IFields [9] = "State";
     IFields [10] = "Zip";
     IFields [11] = "Phone";
     IFields [12] = "Fax";
     IFields [13] = "Email";
     IFields [14] = "Product";
     IFields [15] = "Handling";
     IFields [16] = "Question";
     IFields [17] = "Question2";
     IFields [18] = "Question3";
     IFields [19] = "ReqBy";
     IFields [20] = "RepName";
     IFields [21] = "RepNo";
     IFields [22] = "Notes";
     IFields [23] = "HCP";
     IFields [24] = "Priority";
     IFields [25] = "CaseType";
     
     // Create the body of the email message to be sent to the mailbox.
     // For each IRMS field name, get the corresponding field value from the form and
     // append it to the message body.
     for(i = 0; i < IFields .length; i++)
     {
      // Skip the "SpecCode" field; it's not used, but it was included in the original form.
      if(i == 4) {
       continue;
      }
     
      // Field 19 ("ReqBy") is hard-coded to "Test", as it was in the original form.
      // All other fields get their values from the form.
      if(i == 19) {
       value = fields[i];
      } else if(i == 24) {
       value = dom.selectSingleNode(ns + rootElement + ns + fields[i]).text;
       if (value == "1") {
        value = "International HCP";
       } else {
        value = "";
       }
      } else {
       value = dom.selectSingleNode(ns + rootElement + ns + fields[i]).text;
      }
     
      value = value.trim();
     
      // Only append the field/value pair if the value is not blank.
      if(value != "") {
       messageBody += strB + IFields[i] + "=" + value + strE;
      }
     }
     
     // Use the EmailAdapter object to set the message body and the cc field and submit the email.
     try {
      objEmailAdapter.Intro = messageBody;
     
      var ccField = eventObj.XDocument.DOM.selectSingleNode(ns + rootElement + ns + "cc").text;
      ccField = ccField.trim();
      if(ccField != "") {
       objEmailAdapter.CC = ccField;
      }
     
      objEmailAdapter.Submit();
     } catch(e) {
      //Just catch and ignore any errors.  If we display the error message here,
      //then if the user cancels the submission, it shows a bogus error message.
      //Instead, just set the return status to false so that it doesn't close the form.
      eventObj.ReturnStatus = false;
      return;
     }
     
     // If the submit operation is successful, set
     // eventObj.ReturnStatus = true;
     eventObj.ReturnStatus = true;
     
    }
     
    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    //=======
    function XDocument::OnLoad(eventObj)
    {
     
     var dom = eventObj.XDocument.DOM;
     var repName;
     var repPhone;
     
     // Get the repName and repPhone values from the form.  If the user opened a
     // saved version of this form, these fields will probably already have values,
     // which should not be overridden.
     repName = dom.selectSingleNode(ns + rootElement + ns + "repInfo" + ns + "repName").text;
     repPhone = dom.selectSingleNode(ns + rootElement + ns + "repInfo" + ns + "repPhone").text;
     
     // If either field is empty, execute the prepopulation.
     if(repName == "" || repPhone == "") {
      // Call the web service to prepopulate the current user's information on the form.
      // This could have been done automatically by configuring the data source to retrieve
      // when the form opens.  However, it produces an error message when the user is not
      // connected to the network.  If it is coded here in the OnLoad event,
      // it just silently fails when the user is not connected to the network, which is
      // better.  If the user is connected to the network, it calls the web service from
      // SharePoint server and prepopulates the user's name and business
      // phone number from the SharePoint server.
      var objWSAdapter;
     
      // Get a reference to the GetUserProfileByName data source, and query it.  This
      // calls the web service, and automatically prepopulates whatever fields on the form
      // are linked to it, in this case, the user's name and business phone number.
      try {
       objWSAdapter = XDocument.DataObjects("GetUserProfileByName").QueryAdapter;
       objWSAdapter.Query();
      } catch(err) {
       // Just catch and ignore any errors.
      }
     }
     
     // Reset the values that came from the form if they were not empty.  This is just an easy way
     // to avoid overwriting these values if they had initial values.  It's not easy to try and
     // prepopulate these fields separately from the web service, since the web service call
     // automatically prepopulates both of them at the same time.
     if(repName != "") {
      dom.selectSingleNode(ns + rootElement + ns + "repInfo" + ns + "repName").text = repName;
     }
     
     if(repPhone != "") {
      dom.selectSingleNode(ns + rootElement + ns + "repInfo" + ns + "repPhone").text = repPhone;
     }
     
    }
     
    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    //
    // This button is the "Cc" button on this form.  Clicking it will open the Microsoft
    // Outlook Address Book.
    //=======
    function CTRL41_5::OnClick(eventObj)
    {
     var g_oMapiSession = null;
     var oRecipients = null;
     var dom = eventObj.XDocument.DOM;
     
     // Attempt to create a connection to Microsoft Outlook.
     // An exception most likely means that the CDO component is not installed.
     try {
      g_oMapiSession = new ActiveXObject("MAPI.Session");
      g_oMapiSession.Logon("Default Outlook Profile","",true);
     } catch(err) {
      XDocument.UI.Alert("The Microsoft Outlook Collaboration Data Objects (CDO) component " +
           "may not be installed on your computer. This component must be " +
           "installed in order for the Cc: button to open the address book. " +
           "You can manually type email initials and/or email addresses into the Cc: field.\n" +
           "Error: " + err.message);
     }
     
     // Open the MS Outlook address book, which returns an array of recipients.
     // Loop through the recipients, creating a comma-separated list of recipient names.
     // Store this list in the cc field's value.  This will be picked up later in the OnSubmitRequest
     // event and used in the IRMS email message.
     try {
      oRecipients = g_oMapiSession.AddressBook();
     
      var i;
      var value = "";
      for(i=1; i <= oRecipients.Count; i++) {
       if(i > 1) {
        value += "; ";
       }
       value += oRecipients.Item(i).Name;
      }
     
      dom.selectSingleNode(ns + rootElement + ns + "cc").text = value;
     } catch(err) {
      // Just catch and ignore any errors.
     } finally {
      try {
       g_oMapiSession.Logoff();
      } catch(e) {
       // Just catch and ignore any errors
      }
     }
     
    }
     
    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    //=======
    function XDocument::OnContextChange(eventObj)
    {
     // Set the window title.  This seems to be the only event where this code works.
     Application.ActiveWindow.Caption = "Test";
    }

Page 1 of 1 (1 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.