Submit a Form to a SharePoint Form Library [InfoPath 2003 SDK Documentation]

Submit a Form to a SharePoint Form Library [InfoPath 2003 SDK Documentation]

Office 2003

Applies to:

Microsoft Office InfoPath 2003

For information on Service Pack 1 features for creating a data connection that submits your form to a Windows SharePoint Services form library, see "Connect a form to a SharePoint site" in the InfoPath 2003 Help.

When submitting a Microsoft Office InfoPath 2003 form to a form library on server running Microsoft Windows SharePoint Services, you can add script to the form's OnSubmitRequest event handler to programmatically specify the URL for submitting the form, as described in the following procedure.

  1. Open the form in design mode.
  2. On the Tools menu, select Submitting Forms.
  3. Select Enable submit, select Submit using a custom script from the Submit drop-down list box, and then click OK to open the Microsoft Script Editor.
  4. Add script like the following to the OnSubmitRequest event handler for the form.
    function XDocument::OnSubmitRequest(eventObj)
{
    // If the submit operation is successful, set
    // eventObj.ReturnStatus = true
    var blnSubmitSuccess = false;
    var fFileExists = false;
 
    // Specify the URL of the file you want to submit here.
    var strUrl = "http://myserver/myFormLibrary/MyForm.xml";
 
    try 
    { 
        // Create an XMLHTTP object to transport the file.
        var objXmlHttp = new ActiveXObject("MSXML2.XMLHTTP.5.0");
        // Attempt to open to a form using the specified URL to
        // check if a form with the same name already exists
        // in the form library.
        try
        {
            objXmlHttp.Open("GET", strUrl, false); 
            objXmlHttp.Send(); 
            fFileExists = true;
        }
        catch(e)
        {
            fFileExists = false;
        }
 
        // If no form at the same URL has been found, proceed to submit.
        // If you need logic to replace the previous file, you can call
        // objXmlHttp.Open("DELETE", strUrl, false) to delete the form
        // from the form library before proceeding.
        if (objXmlHttp.Status == 404 || !fFileExists) 
        {
            // Submit the form to the form library. 
            objXmlHttp.Open("PUT", strUrl, false); 
            objXmlHttp.Send(XDocument.DOM.xml);
 
            // Status codes of 200 or 201 indicate that the form
            // has been submitted successfully.
            if (objXmlHttp.Status == 200 || objXmlHttp.Status == 201)
                {
                    blnSubmitSuccess = true;
                }
        }
        else if (fFileExists)
        {
            XDocument.UI.Alert("Submit failed. The file already exists.");
        }
    } 
    catch (ex)
   {
        XDocument.UI.Alert("Submit failed due to the following error.\n\n"
            + ex.number + " - " + ex.description);
   }
    
    if (blnSubmitSuccess)
    {
        XDocument.UI.Alert("The form was submitted successfully."); 
        eventObj.ReturnStatus = true;
    }
    else
    {
        eventObj.ReturnStatus = false;
    }

}

  




Show:
© 2016 Microsoft