Compartir a través de


Introducing the InfoPath SP1 Master/Detail Control

Applies To: Microsoft Office InfoPath 2003 SP-1 Preview

InfoPath SP-1 introduces a number of exciting new built-in controls. One of which is the Master/Detail control. After InfoPath 2003 was released, one of the most common questions on the InfoPath newsgroups was how to implement a Master/Detail type of control in InfoPath. Although this was possible in InfoPath 2003 prior to SP-1, doing so was not easy or straightforward. For this reason, InfoPath 2003 SP-1 now includes built-in support for the Master/Detail control.

The Master/Detail control allows you to designate one control as a master that drives the data in another control which is called the detail. When the user selects an item in the master, the corresponding data in the detail is displayed.

When designing a form template in InfoPath design mode, inserting a Master/Detail control into your form is easy. There are actually two ways to do so. The first way is to use the Master/Detail control in the Controls toolbox. Inserting the Master/Detail control from the Controls toolbox actually inserts two controls – a Repeating Table that is designated as the master and a Repeating Section that is designated as the detail. When you insert the Master/Detail control this way, as long as the “Automatically create data source” checkbox in the Control toolbox is checked, a simple data structure is created in the data source. This structure consists of a group node containing one repeating group node that, in turn, contains four child fields. The master and detail are both bound to the inner repeating group node. In this case, the master and detail are said to be linked by position in the tree. This basically means that if you select the third item in the master control, for example, the data for the third item is displayed in the detail control. This enables you, for example, to build a form that contains basic customer information, such as customer name and SSN, in the master and more detailed information about that customer such as address and phone number, in the detail.

The second way to create a Master/Detail relationship is by manually specifying which control is the master and which is the detail. Although this is a bit more difficult than choosing the Master/Detail control from the Controls toolbox it does give you more control over how the master is linked to the detail. (As mentioned earlier, one way of linking a master control to a detail control is by position. The second way to link a master to a detail is by key field. This type of linking allows you to specify a primary key/foreign key type of relationship where the value of the primary key in the master determines which detail data is displayed. This type of linking is only available when creating a Master/Detail relationship manually.)

To create a Master/Detail relationship manually, perform the following steps:

  1. Insert a Repeating Table control. This control will act as the master. (Only Repeating Tables can act as master controls.)

  2. Open the Repeating Table Properties dialog either by double-clicking on the Repeating Table tab at the bottom of the control or by selecting the Repeating Table and then clicking on the Format | View Properties menu item.

  3. Click on the Master/Detail tab

  4. Click the “Set as master” option button and then type a name into the “Master ID” text box. This ID will be used to specify the master to link to when designating another control as the detail.

  5. Click OK to close the dialog and commit the changes to the Repeating Table properties. (At this point, you will notice that the tab at the bottom of the Repeating Table now contains the text “(master)” which designates that this control is now a master control.)

  6. Now, insert another Repeating Table or a Repeating Section control. This control will act as the detail control. (If you want to link the master to the detail by position, it is better to insert a Repeating Table or Repeating Section control that is bound to the Repeating Table you created in step 1. Link by position is the default behavior when inserting the Master/Detail from the Controls toolbox as mentioned earlier.) If you insert a new Repeating Section control, you will want to add controls inside the Repeating Section in order to display the detail data.

  7. Open the properties dialog for the Repeating Table or Repeating Section as in step 2 above.

  8. Click on the Master/Detail tab

  9. Click the “Set as detail” option button.

  10. From the “Link to Master ID” dropdown, choose the ID that you created in step 4 above.

  11. Now, you have to specify how the master and detail are linked. By default, the master and detail are linked by position. Since we already talked about this type of linking above, click the “By key field” option button instead.

  12. In order for this type of Master/Detail relationship to work, you need to specify which field in the data source is the master key and which field is the detail key.

    1. Click on the data source button to the right of the “Key field (master)” edit box and choose the field from the master that should be used as the master key.

    2. Then, click on the data source button to the right of the “Key field (detail)” edit box and choose the field from the detail that should be used as the detail key.

  13. Click OK to close the properties dialog and commit the changes. (At this point, you will notice that the tab at the bottom of the Repeating Table or Repeating Section now contains the text “(detail)” which designates that this control is now a detail control.)

Now, when you use your form, you will notice that when you select an item in the master, only those detail items whose detail key matches the master key of the currently selected item in the master control will be displayed.

Obviously, if there is no data, no details will be displayed. InfoPath provides a nice way to deal with this situation. When walking through the steps to manually create as Master/Detail relationship above, you may have noticed the option “Copy key field from selected master when inserting detail” which is checked by default. This option designates that when inserting a new detail item, the value of the master key of the item that is currently selected in the master control will be automatically copied to the detail key in the new detail item. This is quite convenient when creating Master/Detail data from scratch.

As you can see, creating a Master/Detail relationship in InfoPath 2003 SP-1 is very easy and is just one of the many new features that were added in direct response to customer feedback.

Comments

  • Anonymous
    April 14, 2004
    Why are Master/Detail not allowed with secondary datasources?

  • Anonymous
    April 15, 2004
    Internal technical limitations prevented us from allowing the Master/Detail control on secondary datasources. However, if you want the Master/Detail control on a database or a web service you can design a form from a data source (which makes it the primary data source). Optionally, you can write business logic that moves data from a secondary data source to the main DOM.

  • Anonymous
    April 15, 2004
    Will the Master/Detail control work if you need the detail to include optional, yet repeating sections? I need to have multiple different sections in the detail. One can select one or more sections to complete. Each section is to be saved as a new detail record tied to the master. Every time I try this, the data entered into the first section repeats in all other sections, presumeably because they're bound to the primary key of the detail table. How can I make this scenario work?

    rculver@alliant-solutions.com

  • Anonymous
    April 15, 2004
    Also, why, when you drop the master/detail control on the page, does it create duplicate master and duplicate detail sections/tables?

  • Anonymous
    April 15, 2004
    The default behavior of the Master/Detail control is to link by position. In most cases, when you are binding by position, you want the Master to show a small subset of data and the Detail to show a more detailed view on the same data. For that reason, we bind the Master and Detail to the same group node.

  • Anonymous
    April 15, 2004
    Clearly I do not understand the purpose of the master/detail. It's not really liken to a parent/child database model, is it? Here's why I ask: I have a section (non-repeating) in which I've place a formatting table with all of the controls of my master record. I deleted the vertical detail sections created by default as well as deleted the 2nd vertical section that repeated the master controls. Now I have one repeating section (non-optional) in a repeating section of my repeating detail section. After entering my maser information, why does the master section show repeated when I click to insert my detail section?

  • Anonymous
    April 16, 2004
    Q: Will the Master/Detail control work if you need the detail to include optional...

    Ross, from what you are describing, the way I would build this is by inserting a choice group inside the detail repeating section. That way the user has a choice of which choice section to complete.

  • Anonymous
    April 16, 2004
    Q: Clearly I do not understand the purpose of the master/detail...

    Ross, it sounds like you are trying to build a Master/Detail relationship where the Master is a Section and not a Repeating Section. The Master/Detail relationship is based on the Master and Detail being repeating controls. The Master has to be a Repeating Table and the Detail can either be a Repeating Table or a Repeating Section. Other controls cannot be used for the Master/Detail relationship. Also, all the controls from the master record must be inside the Repeating Table that is designated as the Master. Likewise, the same is true for the detail fields. I hope this helps.

  • Anonymous
    April 16, 2004
    Thanks for the responses. I think I understand what you're saying. You guys must have had some scenario in mind when you developed this control, but it does not appear that it's along the same lines as a parent/child database structure. What's the point of requiring the master to be in a repeating table? Most people are not, for instance, going to keep clicking the Master "add" to add more Purchase orders; their going to want to open a new form each time. So what the point?

    Thanks again, though. I do appreciate the response and InfoPath.

  • Anonymous
    April 16, 2004
    Q: So what's the point?

    Ross, I'm sorry if I may have miscommunicated the intentions of the Master/Detail. The Master/Detail can be used in two types of scenarios. The first scenario is where the master and detail are linked by position in the data source. In this case, the master and detail may or may not be bound to the same node. The purpose of this type of link is be able to show just a small bit of information in the master but more detailed information int the details. For example, let's say that you have 1000 employees each with detailed information such as address, phone number, department, level, etc. In this case, if you want displaying all this information in one table makes life difficult for whomever is using the form. So, you create a Master that shows only the employee names and departments and a detail that shows the rest of the information. When you click on each employee in the master table the detailed information for each employee shows in the details repeating table or section. In this case, it doesn't matter that the details are in a repeating table or repeating section because one master record is link to only one detail record. (However, technical limitations precluded us from creating the detail as a normal section.)

    The second kind of link is by key field. With this type of linkage you can link a master that is bound to a repeating node in the data source to a detail that is bound to a totally separate repeating node in the data source. You link the master and detail by a key field in both the master and the detail. When you select a record in the master the detail nodes whose key field matches that of the selected master is shown. In this way, you can have multiple detail records for the selected master record.

    Now, why would you use the second type of linkage. One example would be the case of a sales organization. In this case, you have sales people who have multiple order details. The master table displays the sales people. When you select a sales person in the master repeating table all the orders (one or more) for that sales person are displayed in the details.

    I hope this makes sense.

  • Anonymous
    April 16, 2004
    Ross, you may also want to check out the InfoPath public newsgroup. You may be able to find more detailed information about InfoPath (including the Master/Detail) there.

  • Anonymous
    June 01, 2004
    Maybe this is slightly off-topic, but I think it could assist with the earlier feedback regarding master/detail controls and secondary data sources. Jan Tielens has posted a VBscript in his blog (http://weblogs.asp.net/jan/archive/2004/03/10/87466.aspx) that fills out subsequent fields after selection of an initial field from a secondary data source (a sharepoint list in his example, but I don't see why it would not work with other secondary data sources).

  • Anonymous
    June 21, 2004
    I have two repeating tables that retrieves their data from a Microsoft access database,
    for each record "r1" in my table "A" i have many records related to that record("r1") in my table "B"( this is a typical Master/Detail scenario).

    my detail table does not have a column that shows the master key of the master table, so how can i simulate the Master/Detail effect programmatically?
    how can i retrieve programmatically the current row selection in a repeating table?
    something like an "onFocus" or "onSelect" event is needed but i didnt found anything like that.

    With "Master/Detail effect" i mean that when one row is selected in the master table then the detail table updates its rows according to the row selected in the master table automatically.

    Im from Lima-Peru, so sorry if my english is a little hard to understand.

    thanks in advance :)






  • Anonymous
    June 21, 2004
    Im trying to link two repeating tables with the master/detail relation, but when im setting the detail table and i select the master Id i created, the following error message appears

    "The master that you just picked is in an incorrect context"

    where is the problem?

    notice that each one of my repeating tables has a scrolling region as container, that can be the reason for this "context problem"? i think that doesnt make sense.

    thanks in advance

  • Anonymous
    June 22, 2004
    Hi Mario,

    I tried a master/detail relationship between two repeating tables each within a different scrolling region. This worked fine for me. Can you describe in more detail how to repro this issue? Also, you may find more information about this on our public newsgroup.

    - Scott

  • Anonymous
    July 20, 2010
    The comment has been removed

  • Anonymous
    July 20, 2010
    The comment has been removed

  • Anonymous
    July 20, 2010
    Found that thanks. Still having problems with the form though. I would like to select a name from a dropdown list linked to a sharepoint list.  I have go this figured out. where I am blocked is that based on that name I would like to populate two other fields in the form from the same list and I just can't seem to figure out how to do that. any help would be appreciated

  • Anonymous
    August 06, 2010
    I am unable to see/locate the Master/Detail control in InfoPath 2010. Likewise, I don't see a Master/Detail tab when opening the properties window of a repeating table. What's the deal?

  • Anonymous
    August 06, 2010
    this control is only available when designing filler forms. In the Designer, New, under available form templates, select Blank Form (InfoPath Filler)

  • Anonymous
    June 25, 2014
    The comment has been removed