October 2010 - Posts - Jo-Anne Alfafara
in

InfoPath Dev

Jo-Anne Alfafara

October 2010 - Posts

  • Best way to launch forms from SharePoint

    Scenario:

    Whenever you want to expose your forms on a web page the tendency is to want to put a plain hyperlink to your XML file. The problem with this ranges from getting Open/Save dialogs all the time (see below).

    In this tutorial we’re providing the script below that calls OpenXMLDocument from a data view just for this purpose. You may copy this script in a text editor of your choice and save as a .js file.

    function CreateNewXMLDocument(url)
    {
        try{
            // Based on WPQ3combineDocuments()
            var objOpenXMLDoc = new ActiveXObject("SharePoint.OpenXMLDocuments.1");
            var bSuccess = false;
            bSuccess = objOpenXMLDoc.CreateNewDocument2(window , url , url );
        }
        catch(e)
        {
            // Some browsers will not support this feature.
            window.location = url;
        }
    }

    function OpenXMLDocument(url)
    {
        try
        {   
            // Based on WPQ3combineDocuments()
            var objOpenXMLDoc = new ActiveXObject("SharePoint.OpenXMLDocuments.1");
            var bSuccess = false;
            bSuccess = objOpenXMLDoc.EditDocument2(window , url , "InfoPath.Document" );
        }
        catch(e)
        {
            // Some browsers will not support this feature. 
            window.location = url;
        }
    }

    Add the javascript to your website

    1. Create a new folder called “script” underneath C:\Inetpub\wwwroot\wss\VirtualDirectories\80\ and put the JS file in that folder.

    2. So now the JS file can be accessed at http://<SharePointServer>/script/InfoPathOpen.js.

    Add a reference of the script to your website

    1. Now you need to edit your page, in this case, we’re editing a data view from SharePoint designer to add reference to the javascript file.

    2. Open your data view from SharePoint Designer.

    3. Click the code tab found underneath.

    4. Place a reference somewhere in the code. You want to put in a place where it’s not going to be repeated.

    <script type="text/javascript" src="http://<SharePointServer>/script/InfoPathOpen.js"></script>

    Change the link format

    1. In the code tab, find the line called <td class="style1">.

    2. Insert this code just after <td class="style1">:

    <a href="{@Link}" onclick="OpenXMLDocument('{@Link}'); return false;">
    <xsl:value-of select="@DocID" /></a>

    3. Save the changes to your data view.

    Now refresh your list and open the link. In the example below, the DocID link directly opens the form without the pop ups.



    Also, check out Jim's latest blog on how to prevent the Open/Save dialog box in SharePoint 2010 using a code snippet. Jim's technique is similar to what's shown above but does not require code level page editing.
     

  • Side-by Side versioning with Content Types

    Scenario

    Do you have InfoPath forms created in different versions? Want to have old forms shown in old form template and new forms in new form template? No problem!!! Follow this document and you will be able to create side-by-side versioning of InfoPath form using Content Types.

    If you want to use DBXL to map these content types to your SharePoint library, see this previous blog post.

    Design the form (Version 1)

    1. Open a blank form in design mode.

    2. Create the following fields in the form. Notice that “Issue” group is a repeating section.

    3. Drag and drop the fields into the form. Now we are done with creating the form template. Your form will look like this:

    4. Save the form template locally as CustomerContact-v1.xsn. Let’s consider this as version 1 form.

    Design the form (Version 2)

    1. Create the next version (version 2) of the form and name it CustomerContact-v2.xsn.

    2. Change a bit of the schema by adding a new field called “Company” under “CustomerInfo” and make it a required field. Add another new field “DateTime” (of datatype Date) under “Issue” and enter today() as the default value for the field.

    3. Clear the previous display, and drag & drop the new schema into the form.

    4. Change the control of the DateTime field to textbox, and change the display of the field to Read-only.

    5. Go to form template properties and make sure the name of the form template is “CustomerContact-v2”. Save your changes to the form.

    Publish the Form Templates as Content Types

    1. Create a Form Library that will hold the content types (i.e. http://dbxl-vm/MyContentTypes/Forms/AllItems.aspx).

    2. Open the first form template (CustomerContact-v1.xsn) in design mode.

    3. Select File > Publish.

    4. In the Publishing Wizard, enter the SharePoint server root where you want to publish the form template. Click Next.

    5. The key thing here is to choose Site Content Type, click Next.

    6. Select Create a new Content Type and click Next.

    7. In the next window, enter a name for your content type (CustomerContact-v1). Click Next.

    8. Specify a location and file name for the form template (e.g. http://dbxl-vm/MyContentTypes/Forms/CustomerContact-v1.xsn), and then click Next.

    9. When asked to choose the columns you want to display in the SharePoint library, add the fields and click Next.

    10. Click Publish. When done, click Close. Your form template will be published as content type.

    11. Repeat steps 1-10 to publish CustomerContact-v2.xsn to the same content type library.

    Create a new Form Library and add the Content Types

    1. Create a new form library.

    2. Go to your SharePoint Form Library -> Settings -> Form Library Settings -> Advanced Settings.

    3. Select Yes to allow management of content types, and click OK.

    4. Back in the Form Library Settings, select Add from existing site content types under Content Types section.

    5. In the Add Content Types page, select the two content types that were published in the SharePoint site (CustomerContact-v1 and CustomerContact-v2) and click Add. Click OK.

    6. Back in the Form Library Settings, select Change new button order and default content type under the Content Types section.

    7. Choose CustomerContact-v1 as Position 1, which makes it the default content type, and CustomerContact-v2 as Position 2. Then uncheck the visible check box for “Form”. Click OK.

    Create two versions of the form

    1. In the form library, click the down arrow for New Document. You can see that we can choose the templates from both versions.

    2. Select CustomerContact-v1.

    3. Fill out the Customer Contact form and save it as “Version1Form”. Close the form.

    4. Now, select CustomerContact-v2 under the New Document.

    5. Fill out the Customer Contact form and save it as “Version2Form”.

    6. Now we have two versions of the InfoPath forms both using their own templates to save information.

  • How to map two document types in a SharePoint Library using Content Type mapping

    Do you want to submit using two form templates from one SharePoint library to DBXL? You can do this now in DBXL v2.4 by mapping to SharePoint using content types.

    Let’s walk through the steps on setting up two content types and mapping them to DBXL.

    Pre-requisites

    Design the Form

    We will begin by designing our forms and declaring the document type names into an XML. Declaring the document type name in XML is required if your form has code. You can skip this section if your form is code-free.

    1. Design the first form. In this example, we will be adding three nodes to our main data connection (Name, Author, and Description).

    2. We will label the form as Content Type1, so we can better identify the two forms later in this tutorial.

    3. Declare Document Type name in XML.

    a. Create an xml file with one node, which declares the name of the Document Type that you will be using. Its contents may look like this:

    <declaration>
    <doctypename>ContentType1</doctypename>
    </declaration>

    b. Save this xml document to your local drive.

    c. Open the form template in design mode in InfoPath.

    d. Click on Tools > Data Connections and click Add.

    e. Select Create a new connection to and select Receive data. Click Next.

    f. Select XML document and click Next.

    g. Click Browse and select the xml file that you created in step 3a.

    h. Click Next twice and then click Finish. If you receive a warning, click Ignore.

    4. Create a submit data connection.

    a. Select Tools > Data Connections and click Add.

    b. Select Create a new connection to and select Submit data. Click Next.

    c. Select To a Web service and click Next.

    d. Enter the URL to the DBXLDocumentService, usually http://<servername>/QdabraWebService/DBXLDocumentService.asmx, and click Next.

    e. Select SubmitDocument from the list of operations and click Next.

    f. Double click the tns:docTypename parameter and select the secondary xml connection
    created in Step 3 from the data source dropdown.

    g. Expand the tree to display the node, select the doctypename node, check the checkbox for
    Submit data as string and click OK.

    h. Select the tns:xml parameter, select the Entire form toggle, and check the checkbox for
    Submit data as string.

    i. Double click the tns:name parameter and select the field Name from the main data source. Check Submit data as a string.

    j. Double click the tns:author parameter and select the field Author from the main data source. Check Submit data as a string.

    k. Double click the tns:description parameter and select the field Description from the main data source. Check Submit data as a string.

    l. Click Next, enter a name for the submit data connection, and then click Finish. If you receive a warning, click Ignore. Then close the data connections dialog box.

    5. Configure a Submit button.

    a. Add a button and double click on it to open the Button Properties.

    b. Change the Action dropdown to Submit and click on Submit Options.

    c. Check the checkbox for Allow users to submit this form and select Web Service from the
    Send form data to a single destination dropdown.

    d. Make sure that the Web Service submit data connection created in step 4 is selected in the
    Choose a data connection for submit dropdown.

    e. Click OK twice to close the dialogs.

    6. Save the XSN in your local drive. For the purposes of this tutorial, we will call the form template ContentType1.xsn.

    7. Repeat steps 1-6 to create your second form template, saving it as ContentType2.xsn. You may change the form by adding new fields. Note that when you create the XML, make sure that you declare a different document type name.

    Publish the Form Templates as Content Types

    1. Open the first form template (ContentType1.xsn) in design mode.

    2. Select File > Publish.

    3. In the Publishing Wizard, enter the SharePoint server root where you want to publish the form template. Click Next.

    4. In the next window, select Site Content Type option, and then click Next.


     
    5. Next, you may opt to create a new content type or update an existing one in your site. In this case, we are creating a new content type.



    6. In the next window, enter a name for your content type (i.e. ContentType1). Click Next.

    7. Specify a location and file name for the form template (e.g. http://dbxl-vm/MyContentTypes/Forms/ContentType1.xsn), and then click Next.

    8. When asked to choose the columns you want to display in the SharePoint library, add the fields and click Next.

    9. Click Publish. When done, click Close. Your form template will be published as content type.

    10. Repeat steps 1-9 to publish ContentType2.xsn to the same content type library.

    Create a new Form Library

    1. Create a new form library.

    2. In your form library, select Settings > Form Library Settings.

    3. Under General Settings, click Advanced settings.

    4. Select Yes to allow management of content types, then click OK.

    5. Back in the Form Library Settings, select Add from existing site content types under Content Types section.

    6. In the Add Content Types page, select the two content types that were published in the SharePoint site and click Add. Click OK.

    7. Back in the Form Library Settings, select Change new button order and default content type under the Content Types section.

    8. Uncheck Form as default content type and click OK.

    Create the Document Types


    1. Open the DBXL Administration Tool or DAT.

    2. Click New Configuration.

    3. Click the XSN File attachment field.

    4. In the File name field, enter the URL to your first content type (ContentType1.xsn).

    5. Click Insert. Your content type will be attached to DBXL.

    6. Enter a name for the Document Type. Make sure that your Document Type name matches the same name that was hardcoded in your XML file.

    7. Click Save.

    8. Create your second document type (ContentType2.xsn), repeating steps 3-7.


    Create the SharePoint Mappngs

    1. In DAT, click Edit Configuration for ContentType1.xsn.

    2. Click on the SharePoint tab.

    3. Click Insert Mapping.

    4. Enter the URL to the form library you created earlier.

    5. Check the Content Type check box. You’ll notice that a Content Type Url field is now displayed.

    6. Enter the Url to your content type (e.g. http://dbxl-vm/MyContentTypes/Forms/ContentType1.xsn

    7. Your mapping should now look like this:

    8. Click Save.

    9. Click Catalog.

    10. Click Edit Configuration for your second content type (ContentType2.xsn).

    11. Repeat steps 2-6, using the second Content Type Url:

    12. Click Save.

    Test the solution

    1. In Internet Explorer, open the SharePoint form library you created.

    2. Click on New.

    3. Select ContentType1 or ContentType2.

    4. Fill out the form and click Submit.

    5. You can open, edit and re-submit the documents by clicking on each item in the SharePoint library.

    6. In DBXL, select a document type and click new to open a blank form. Fill out the form and click Submit.

    NOTE: When your form has code, do not click New in DBXL. Instead, click on the Download button.

    7. You can open, edit and re-submit the documents via their document handler URL, that is, http://<servername>/QdabraWebService/Documents/<docID>/<docID>.xml, or by selecting them from the Documents tab in DAT.

     

Copyright © 2003-2012 Qdabra Software. All rights reserved.
View our Terms of Use.