Greg Collins
in

InfoPath Dev

This Blog

Syndication

Greg Collins

  • Choose Your Section Wisely

    I uncovered this problem on 2004-08-18 while hard at work creating a form. It caused me quite a headache at first until I was able to narrow and then finally track down the problem. I've reported it to Microsoft.

    DESCRIPTION:

    The problem seems to stem from inserting a non-repeating group into the view that is contained within repeating group, which is not inserted into the view. The non-repeating group is inserted as a non-repeating Section.

    Here's the walkthrough to reproduce the problem:

    1. Launch InfoPath.
    2. Create a new blank form
    3. Open the Controls task pane.
    4. Insert a Repeating Section in the view.
    5. Insert a Section in the Repeating Section.
    6. Insert a Text Box in the Section.
    7. Select everything in the view and delete it.
    8. Open the Data Source task pane, and then expand the data source tree.
    9. Insert group2 as a Repeating Table in the Section.
    10. Insert group1 as a Section at the bottom of the view. This section would ultimately have conditional visibility added to it.
    11. Click inside the Section to set the insertion point.
    12. Right-click on group2 and then choose More | Section (i.e. non-repeating section)
    13. Drag and drop field1 into the group2 Section.
    14. Preview the form.

      Note that when clicking on the Section that it gets highlighted blue just as the Repeating Table does. We need to eliminate this blue highlighting.

    15. Close the preview.
    16. Delete the group2 Section.
    17. Click inside the Section to set the insertion point.
    18. Right-click on group3 and then choose More | Section (i.e. non-repeating section)
    19. Drag and drop field1 into the group3 Section.
    20. Preview the form.

      Note that when clicking on the Section that it no longer gets the blue highlighting. This worked!

    21. Close the preview.
    22. Choose Extract Form Files from the File menu, choose a folder and then save.
    23. Close InfoPath.
    24. Open the folder you extracted the form files to.
    25. Right-click on the manifest.xsf file and choose Design.

      An error message appears with the following message:

      InfoPath cannot open the following form: {Folder_Path}\manifest.xsf
      Microsoft Office InfoPath cannot open the selected form.


    26. Click OK, and exit InfoPath.
    27. Edit the view1.xsl file in a text editor, such as NotePad.
    28. Search for [1]. You'll find the following line:

      <xsl:apply-templates select="my:group2[1]/my:group3" mode="_13"/>


      Note that the [1] means to select the first instance of group2. This indicates that we chose a non-repeating section when we inserted group3 in the view.

    29. Delete [1], save and then close the view1.xsl file.
    30. Right-click on the manifest.xsf file and choose Design.

      InfoPath opens the form template, but now there are red errors on the group3 Section and on field1.

    When we used a non-repeating Section using group2, it worked, but we had the blue highlighting. The apply-templates in the view for that scenario looked like this:

    <xsl:apply-templates select="my:group2[1]" mode="_12"/>

    So why does InfoPath work when selecting only the first instance of a group, but not when selecting a field within that first instance? Why can you preview the form, but once you save it, you can no longer open it?

    WORKAROUNDS:

    I currently do not know of a workaround for this.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Make a Filter Work Automatically With No User Interaction

    When you add a filter to a control such as a repeating table, the filter should be able to work automatically (i.e. require no user interaction). If you run into a situation where this is not working, you can try the following steps.

    1. Make a backup of your form template.
    2. Extract your form files to a folder.
    3. Edit the manifest.xsf file in a text editor.
    4. Search for and delete any attribute useFilter="yes" on an xsf:editWith element. Don't delete the element, just the attribute.
    5. Search for and delete any xsf:button elements with the attribute action="xCollection::refreshFilter".
    6. Save the manifest.xsf file and close the text editor.
    7. Right-click the manifest.xsf file and choose Design.
    8. Test the changes.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Remove a Form Template from the InfoPath Cache

    You might encounter a situation where forms continue to open in a form template that you deleted. This may seem strange until you learn that InfoPath caches form templates. Although you deleted the physical copy, the cached version still exists.

    InfoPath caches form templates the first time they are used. This enables you to use online InfoPath forms when you are offline. It also improves performance. Once both the physical and cached form templates are deleted, forms that use that form template can no longer be opened in InfoPath.

    You can also remove a form template from the InfoPath cache without deleting the physical copy. This is occasionally necessary, when developing a form, in order to view the changes that you have made. In this task we will learn how to remove a form template from the InfoPath cachce.

    Remove a form template from the InfoPath cache:

    1. Launch InfoPath.
    2. In the Fill Out A Form dialog box, select the All Forms category.
    3. Select the form template you want to remove from the InfoPath cache.

    If you do not see the form template listed, select All Forms from the list of Form Categories at the top left of the Fill Out A Form dialog box.

    1. Click Remove This Form from the list of Form Tasks at the top right of the dialog.
    2. Close InfoPath.

    If the above steps fail and you find the old for template is still loading you can try one of the following:

    1. Choose Run from the Start menu, type infopath /cache clearall, and then click OK.
    2. Manually delete cached InfoPath template in the cache folder located at:

      [Vista]: C:\Users\<Username>\AppData\Local\Microsoft\InfoPath\FormCache2
      [XP]: C:\Documents and Settings\<Username>\Local Settings\Application Data\Microsoft\InfoPath\FormCache2

    Try it:

    Once you have deleted both the physical and cached copy of the form template, launch a form file created from that form template. InfoPath will still be launched, but you will receive a warning dialog box stating that the form template cannot be found.

    Open the Form XML Without InfoPath:

    If you want to prevent the form from opening in InfoPath at all, then you need to remove two tags, known as processing-instructions, from your form. Using a text editor, such as Notepad, remove the following two processing-instructions from your form .xml file:

    <?mso-infoPathSolution . . . ?>
    <?mso-application . . . ?>

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Display a Linked Picture from a Parameterized Active Server Page

    You might need to display a custom picture in your form based on field values. You can do this using an Active Serve Page that takes parameters. Your Active Serve Page might return a barcode, a map, a photograph, or any other kind of picture. Your form will use the Linked Picture control.

    In this task we will show how to set up the linked picture binding to retrieve a picture from an Active Server Page using two field values from the main data source. We assume that you already have an existing Active Server Page capable of accepting parameters and returning a picture. Let's start by designing a new blank form.

    Add the parameter fields to your main data source:

    1. Open the Data Source task pane.
    2. Add two Text Fields named Param1 and Param2.

    Create a custom linked picture binding:

    1. Open the Controls task pane.
    2. Insert a picture into the view.
    3. In the Insert Picture Control dialog box, select As A Link, and then click OK.
    4. Double-click the picture control in the view.
    5. In the Picture Properties dialog box, replace the XPath with the following:

    concat("http://server/picture.asp?param1=", my:Param1, "&param2=", my:Param2)

    Make the appropriate adjustments to the URL to match your server, Active Serve Page and parameter names.

    1. Clear the Allow The User To Browse For New Pictures check box, and then click OK.

    Try it:

    Preview your form. Assuming your URL is valid and the ASP page is working correctly, when you enter valid values into the Param1 and Param2 fields, you will see your picture correctly updated.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Prevent the File Download Security Warning

    After installing InfoPath 2003 SP1 you may have noticed when you try to open an InfoPath form template (see Figure 1) or form (see Figure 2) from a Web site or from SharePoint that a new File Download dialog box appears. These warning dialog boxes can quickly become annoying. You can prevent these dialog boxes from appearing by following the steps below.


    Figure 1. The File Download dialog box for InfoPath form templates.


    Figure 2. The File Download dialog box for InfoPath forms.

    Prevent the File Download dialog box for InfoPath form templates:

    There are two ways to prevent the File Download dialog box for InfoPath form templates. The easiest way to do it is to clear the Always Ask Before Opening This Type Of File check box at the bottom of the File Download dialog box (refer to Figure 1). The second way is to follow these steps:

    1. In Windows Explorer choose Folder Options from the Tools menu.
    2. On the File Types tab of the Folder Options dialog box, Type XSN.

    The list will automatically scroll and select Microsoft Office InfoPath Form Template.

    1. Click Advanced
    2. Clear the Confirm Open After Download check box, and then click OK.

    Prevent the File Download dialog box for InfoPath forms:

    1. Click in the Registered File Types list box to set focus, and then type INFO.

    The Registered File Types list box will automatically scroll and select Microsoft Office InfoPath 1.0 XML Document, as shown in Figure 3.


    Figure 3. Selecting the InfoPath XML Document file type.

    1. Click Advanced
    2. Clear the Confirm Open After Download check box (as shown in Figure 4), and then click OK.


    Figure 4. Preventing the File Download dialog box from appearing.

    1. Click Close.

    With these changes in places, you will no longer receive this dialog box when you open an InfoPath form template or form from a Web site or from SharePoint.

    These steps are not easily deployable. However, in the future, another option may present itself. Until then users can either click Open on the dialog box, or prevent the dialog box from appearing by following the steps above.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Populate a Drop-Down List Box via a Secondary Data Source

    One great feature of InfoPath SP1 is the ability to quickly populate a drop-down list box from a variety of data sources. One such data sources is an XML file that has been added to the form as a secondary data source. A common mistake is binding the Drop-down List Box control to the wrong data source.

    Secondary data sources are very helpful to keep your main data source clean and pure for holding only essential form data. The values in the secondary data source may be updated during the life of the form, but they are never saved as part of the form. Only the values in the main data source are stored when the form is saved or published.

    Binding is something that takes place between a control (such as a Drop-Down List Box) and a data node. When you select a data node in the Data Source task pane and drag it into the view, or right-click and choose a control type, the control in the view is "bound" to that data node--meaning that any value held by the control will be the stored value in the data node.

    If a control is bound to a secondary data source, the stored value will persist for the life of the form. Once the form is closed, however, the value is lost. If a control is bound to the main data source, the value will be persisted as part of the saved form.

    To correctly use a secondary data source to populate a Drop-Down List Box and have the selected value stored as part of the same form, the control needs to be bound to the main data source, but populated from the secondary data source. This can be done with the following steps:

    Insert a Drop-Down List Box control bound to the main data source:

    1. From the Data Source task pane, select Main from the Data Source drop-down list.
    2. Select the data node you want the value to be stored in, right-drag it into the view, and then release in the location where you want the control placed.
    3. From the context menu that appears when you release the right-drag, select Drop-Down List Box.

    Populate the Drop-Down List Box from a secondary data source:

    1. Double-click the Drop-Down List Box control.
    2. In the Drop-Down List Box Properties dialog box select Look Up Values In A Data Connection.
    3. Choose the secondary data source from the Data Connection drop-down list.
    4. Click the Select XPath button to the right of the Entries field.
    5. Select the node that will be used to populate the values, and then click OK.
    6. If necessary, use the Select XPath buttons to the right of the Value and Display Name fields to make appropriate node changes.
    7. Click OK to close the dialog box.

    Your drop-down list is ready. Its values will be populated from the secondary data source, but the selected value will be stored in the main data source when the form is saved or published.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Enabling XP-Themed Buttons in Task Panes and Modal Dialogs

    One anomaly you will run into if you have the Windows XP Themes turned on and are using a task pane or a modal dialog in your form is that buttons in these HTML pages will look different than those inside the InfoPath form view. This is because the HTML pages within InfoPath do not have this feature turned on. You can correct this by adding the following META tag to the top of your HTML page:

    <meta http-equiv="msthemecompatible" content="yes">

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Enable InfoPath E-Mail Features

    Most people will never run into this problem, but a few of you will and it could drive you nuts.

    The InfoPath application includes the e-mail features Send Form As Attachment in the designer, and Send To Mail Recipient in the editor. These are both found under the File menu. If for some reason these are not present, one or more issues will need to be resolved. The three most likely issues are as follows:

    1. Outlook is not installed.
    2. Outlook does has no configured profile.
    3. Outlook in not the default e-mail client.

    InfoPath 2003 requires Outlook 2003—an older version simply will not work. If either of these two situations are present on your machine, the above e-mail features will not only be disabled, but they will not appear in the menus at all. The Submit Data As An E-Mail Message data connection might still work, but it also might not.

    To enable these InfoPath e-mail features, correct the above issues by ensuring that Outlook 2003 is both installed and set as the default e-mail client.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Submit to a SQL Database

    When creating a new form from a SQL database connection, there are a couple of things to remember in order to enable the Submit To Database feature.

    1. The SQL tables used must have a primary key, unique constraint, or unique index. Without this you will receive the following error in the summary of the Data Connection Wizard:

      Submit status: Not allowed - One or more of the tables in the data source do not have a primary key, unique constraint, or unique index.

    2. The SQL database tables must not include the following data types: image, ntext, text. These are considered long data types and are not supported within InfoPath. If your tables include any of these data types you will receive the following error in the summary of the Data Connection Wizard:

      Submit status: Not allowed - One or more of the columns in the data source has a long data type (text, ntext, hyperlink or image). Long data types are not supported.

    3. Other things may prevent you from submitting to your database. Here's a couple of other reasons that will prevent you:

      Submit status: Not allowed - A table is being used many times

      Submit status: Not allowed - A many to one relationship might exist between two tables in the data source.

    If you have successfully satisfied the conditions, the summary of the Data Connection Wizard will inform you that submit is enabled. To then submit to your database, perform the following steps:

    1. Drag a Button control into the view from the Controls task pane.
    2. Double-click the new button to open the Button Properties dialog box.
    3. On the General Tab, change the button action to Submit.
    4. On the Submitting Forms dialog box, the Submit To drop-down list box should have the value Database pre-selected. Click OK to accept the defaults.
    5. Click OK again to close the Button Properties dialog box.

    That's it -- you're done! You are now set up to submit your form entries to your SQL database.

    ©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • User Role Evaluation Order

    InfoPath evaluates the User Roles in top-down order, as they appear in the Manage User Roles dialog box. But there is no built-in way to reorder these roles. Manually editing the manifest.xsf file is the only way to accomplish this. Here are the steps:

    1. Extract the form files to a folder, and then close the InfoPath designer. InfoPath places a lock on the files it uses. Thus you can't modify the manifest.xsf with the form still open in InfoPath.
    2. Use a text editor to open the manifest.xsf file, and then locate the <xsf:roles> tag.
    3. Cut-and-paste each <xsf:role/> tag into the order you want your roles to be evaluated.
    4. Save the modified manifest.xsf file and close the text editor.
    5. Open the saved InfoPath form and test your changes.

    If a user belongs to two or more roles, InfoPath will stop evaluating at the first match. If the Open Rules use the User Role as a condition, let's say for deciding which view to switch to, this can lead to anomalies unless taken into account. To fix a scenario such as this, the Roles will have to be ordered in such a way as to alleviate this, or more Open Rules will need to be added to take this into account, or code will need to be used in place of Open Rules depending on how complex a scenario is required.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

    Posted Jul 26 2004, 03:54 PM by Greg Collins with no comments
    Filed under:
  • Match Control Sizes to Font Sizes

    While developing forms in InfoPath, it is likely that you will one day need a label for a check box or an option button that uses a font size other than the default 10pt. Using a different font size will make the control simply not look right next to the label. Luckily these controls are resizable (this is true for both V1 and SP1).

    Using a larger font size is fairly straight forward: it's just a matter of finding the correct control size. But using a smaller font size can start shifting the control around and out of place. This is easily corrected by adjusting the margins on the control.

    You can see these techniques demonstrated in my example form: Rightsizing Check Boxes and Option Buttons. Also, the following table lists good control sizes for the InfoPath's standard font sizes.

    Font Size

    Control Size

    Margins (T, L, B, R)

    8pt

    10px

    0px, 4px, 3px, 2px

    10pt

    20px

    n/a

    12pt

    22px

    n/a

    14pt

    24px

    n/a

    18pt

    30px

    n/a

    24pt

    36px

    n/a

    36pt

    48px

    n/a

     

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Flaky Data Validation Visuals

    STATUS: Fixed in InfoPath 2003 SP1.

    SCOPE:

    • Occurs in both V1 and SP-1.
    • Not language specific.

    DESCRIPTION:

    On 2004.07.23, I was sent a form to help track down an issue where dashed red lines that appears when data for a particular field is invalid. After a little playing, I was able to narrow it down to a simple repro. It’s an interesting bug.

    REPRO STEPS:

    1. Start with a New Blank Form.
    2. Insert a single row/col table (TABLE_1).
    3. Insert another single row/col table (TABLE_2) inside TABLE_1.
    4. Insert a text box into TABLE_2.
    5. Double-click the text box and change its datatype to a Whole Number.
    6. Preview.
    7. Type invalid characters into the text box (i.e. “abc”). A dashed red border appears.
    8. Move your mouse all around, and click over the text box:

      Nothing special happens.

    9. Close the preview.
    10. Add a background color to TABLE_1.
    11. Preview.
    12. Type invalid characters into the text box (i.e. "abc"). A dashed red border appears.
    13. Move your mouse all around, and click over the text box:

      Notice that the dashed red border acts flaky, disappearing, etc.

    This doesn't happen with a single table, only when there are nested tables. There can be any level of table nesting. Also the background color can be on any table except the one that holds the control for this problem to occur. The datatype does not seem to matter—just that it is invalid. Adding a background color to the control's table does not seem to alleviate the problem.

    WORKAROUNDS:

    Presently the only known workaround is to either not nest tables, or to make sure that the background color is present only on the inner-most table.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Master-Detail Table Row Reordering: Safety Tips

    STATUS: Fixed in InfoPath 2003 SP1.

    DESCRIPTION:
    I uncovered this previously unknown problem on 2004-07-17 while updating the InfoPathDev Web site using an RSS 2.0 Generator InfoPath form I created. I've reported it to Microsoft.

    I wanted to reorder the list of InfoPathDev example forms to put the more popular ones at the top. I posted my example form: Reordering Table Rows, which demonstrated how to create buttons to move rows in a table up or down. I use this technique in the RSS 2.0 Generator in a Master-Detail Table. The reordering buttons are in the Master table.

    The first row I moved up worked just fine; then when I attempted to move it up again, InfoPath crashed. After that, it crashed time after time. At first I couldn't figure out what was going on—and what was worse was that the debugger commands I placed at the top of the OnClick handlers to attempt to locate the source of the problem were never reached before InfoPath would crash. (I made sure I was a good boy and sent in all of the crash reports.)

    While continuing to play, I was able to reorder a table row without a crash. My assumption was correct: the crash was avoided by first selecting the row I was attempting to reorder. When the row was selected, the reordering worked fine, but without the selection InfoPath crashed.

    The failure is the following:

    CiceroUIWndFrame: INFOPATH.EXE - Application Error
    The instruction at “0x30528af9” referenced memory at “0x00000000”. The memory could not be “read”.

    This problem doesn't always manifest itself. It seems to be based on the complexity of the contents to be reordered. I have some XML files I have no problem reordering, while others that are more complex and crash every time. I haven't yet tested whether this problem is also manifest using a standard Repeating Table or Repeating Section.

    Luckily there is a workaround, even though having to select each row before reordering quickly becomes quite a tedious task.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Order of Processing at OnClick

    In InfoPath, the order of processing when a user clicks a button is:

    1. Rules
    2. Code

    When you write your OnClick event handler, take into account that any rules associated with the button will be processed before the code is reached. This can be very useful, but can also create some headaches if not understood.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

  • Populate a Drop-Down List Box via Code

    NOTE: This article was written for the original InfoPath 2003, which did not support secondary data sources. You can still use code to populate a drop-down list box, but the better approach is to have the drop-down list populate from a secondary data source, and then use code to add nodes to that list in your secondary DOM.

    - - - - - 

    Populating a drop-down list box in InfoPath is easy, but you might need to something more complex than the designer allows. This is possible with some work on your part. Although very powerful, populating a drop-down list box via code requires that you use a Preserve Code Block.

    In this task we will populate a drop-down list box via code. The drop-down list box will exist inside of a section that will be used to create the Preserve Code Block. Let's start by designer a new blank form.

    Design the view:

    1. Open the Controls task pane.
    2. Insert a Section into the view.
    3. Insert a drop-down list box into the section.

    Write code to return a list of options:

    1. Press ALT+SHIFT+F11 to open the Microsoft Script Editor.
    2. Insert the following function:

    Java Script:
    function PopulateDropdown(sSelectedValue)
    {
        return "<option value=''>Select...</option><option value='Test'>Test</option>";
    }

    C#:
    public string PopulateDropdown(string sSelectedValue)
    {
        return "<option value=''>Select...</option><option value='Test'>Test</option>";
    }

    1. Save your code, and then exit the Microsoft Script Editor.

    Modify the view .xsl file to create a Preserve Code Block:

    1. In the InfoPath designer, choose Extract Form Files from the File menu.
    2. Select a location to save your extracted form files to, and then click OK.
    3. Close InfoPath to release the lock it places on your form files.
    4. Using a text editor, open your view .xsl file.
    5. Locate the xsl:template that contains your drop-down list box.
    6. Replace the mode="_nn" attribute with mode="xd:preserve" for both the xsl:template element and its associated xsl:apply-templates element.

    The mode attributes will have matching values in both the xsl:template and xsl:apply-templates elements.

    1. Replace all the option elements listed for this drop-down list box with the following code:

    <xsl:value-of select="xdExtension:PopulateDropdown(string(my:BoundField))" disable-output-escaping="yes"/>

    Where my:BoundField is the same value as that of the xd:binding attribute on the select element.

    1. Save the view .xsl file, and then close the text editor.

    Try it:

    1. Launch your modified solution by double-clicking the manifest.xsf file.

    In the InfoPath editor you will see a drop-down list populated with Select... and Test.

    1. Choose Design This Form from the Tools menu.
    2. In the InfoPath designer you will see a red box indicating your Preserve Code Block.

    You can now modify the PopulateDropdown function to process whatever information is required to populate your drop-down list. The string returned must not contain any XSL code, but only contain properly formatted HTML with option elements.

    You will need to use the sSelectedValue parameter to identify which of the option elements is the currently selected option. You must make sure that, in your code, you set the selected="selected" attribute on the correct option element. Otherwise the drop-down list in the view will never show the selected value, but will instead always revert back to displaying the first option in the list.

    This technique is demonstrated in my example forms: Fully Editable Drop-Down List Box and Moving Items Between List Boxes.

    ©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

More Posts « Previous page - Next page »
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.