March 2009 - Posts - Hilary Stoupa
in

InfoPath Dev

Hilary Stoupa

March 2009 - Posts

  • Locked Schema Got You Down?

    Sometimes we want to create a new template off an existing schema. Microsoft has a great article here (EDIT: that link seems dead, but currently a copy is available here), but for those of you who have already created a form off an existing schema, and just want to know how to unlock it, it can be a bit much to dredge through (also, they don't even mention the little .xsf hack I'm going to show you....). Fortunately, you have me, and I feel your pain.

    The Problem

    You saved a beloved form as source files, because its schema was perfect, and you want to base another form off of it. You create a new form template, chosing XML or Schema for the source:
    Base off xsd

    and you happily design away... until you want to add a field. Or change the name of an existing field. That's when you realize.... you're stuck:
    Locked Schema

    See those little locks on the data fields? And at the bottom of the Data Source Task Pane, Add a Field or Group is grayed out....
    Add fields

    The Reason

    If you read the article I've linked in the first paragraph, it says:

    When you design a form that is based on an external schema, Microsoft Office InfoPath 2007, or Microsoft Office InfoPath 2003 assumes that the schema is finalized and therefore prevents any modification of the schema in the Data Source task pane.

    So there you have it. InfoPath figured you were perfectly happy with the schema when you built the form off it.

    One Solution

    You can manually add elements to your schema. Save your form as source files and open myschema.xsd in a text editor. Here is my original schema:
    Original Schema

    And now I've added another string field named String2:

    When I save my change and open manifest.xsf in design mode, I can see my newly added field:
    New field

    Another Solution

    But what if you just want it unlocked, so you can add fields like a normal old data source? For that, again, we need to save as source files. Open manifest.xsf with a text editor. Look for your schema file in the files element. You'll see a property named editability which has helpfully been set to 'none':

     

    Set this property to 'full':

     

    Save your changes, and open your template in design mode again:

    All your fields will be fully editable.

    The Usual Warnings Apply

    Save a copy of your form someplace safe before manipulating form files. This is by no means a full discussion of potential pitfalls that can be encountered -- more information on xsf structure is available here. Happy unlocking!
     

  • First, Do No Harm....

    ... to existing xml files. We've all had to make modifications to production forms, and some of us have failed to test the form with existing xml files until after we've redeployed our changes. I stand among the guilty. I think I thought if I clicked Preview often enough, and entered some likely looking dummy data, all would be well. And I'd find myself rolling back to a previous version of the form because *something* didn't work as anticipated when I opened the existing xml with the new template.

    InfoPath has a feature that can protect us from these little mishaps--it will let you preview your form with an existing xml file. In InfoPath 2003, under File/Preview you can select With Data File and in InfoPath 2007 you can go to Tools/Form Options/Preview and enter a path to the data file you wish to preview with:
    Preview tab

    What kinds of mishaps will this save you from? Well, imagine you have added a new field to your form. Perhaps you have some conditional formatting that was based on the value of a different field, and you've changed it to use the new field....what value will your old xml have in that field? Did you remember to set your form to upgrade exsisting xml files? (Under Versioning in the screenshot above, just in case you forgot....) Maybe you changed an open rule, not realizing it did something vital -- all of these things can be hard to catch when you are previewing a new blank form each time.

    So preview without data during design, but also take the time to preview with data -- production quality, if you have it. When you go to deploy your changes, you won't have any surprises....and unlike, say, birthday cake, this is a *good* thing in the form design world.

    EDIT: One thing I forgot to warn you about. If you leave a file location in this box and then delete the XML -- guess what? Your form won't preview. In InfoPath 2007, you get a warning dialog with NO info:
    Preview warning

    This is very helpful, don't you think? You can open the form. But you can't preview the form. After you get done bashing your head against the desk, you can go clear the file path out of the Preview settings.

    But with InfoPath 2010, we get a slightly better error:
    Preview error

    Not a good error. But a better error.

    The moral is: remove the path to your preview XML prior to saving and closing your form. Future you will thank present you!

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