Repeating fields: Copy individual nodes using qRules - Ernesto Machado
in

InfoPath Dev

Ernesto Machado

Repeating fields: Copy individual nodes using qRules

Using qRules you can use the commands CopyTable and MoveTable to copy or move an entire table.

But what about copying individual repeating fields? We can do this by using Insert and a couple of InfoPath tricks. The steps below illustrate a simple example from which you can extrapolate others.

First we need to design our form.

1.    Create a new, blank InfoPath form and inject it with qRules v1.7.

2.    Create a data source as seen in the screenshot below.

 

3.    Go to Tools > Data Connections and create a new data connection that retrieves data from an xml file every time the form is opened. Here is a screenshot of my xml file.

 

Your secondary data source will look like this:

 

4.    Right-click on the repeating node called name and select Repeating table to insert it into the view.

 

5.    Next to each the text field, insert a button. Double-click on it and change its Label to “Copy over”.

6.    Right-click on the repeating node in the main data source and select Repeating table to insert it into the view.

By now, your view looks like this:

 

We don’t want the destination table to have any rows when the form loads.

7.    Click on Tools > Default Values, uncheck the repeating field in the main data source, and click OK.

 

Now we need to configure our rules.

8.    Double-click on the button and click Rules.

9.    Click Add, then click Add Action.

10.    Select Set a field’s value from the Actions dropdown.

11.    Click on the icon next to Field and select the Command node in the QdabraRules secondary data connection.

12.    For Value, enter the command we will execute: Insert /parent=/my:myFields /child=/my:field1 /count=1. Click OK.

13.    Click Add Action.

14.    Select Set a field’s value from the Actions dropdown.

15.    Click on the icon next to Field and select the repeating field in your main data source.

16.    Click on the icon next to Value, click on Insert field or group and select the repeating node in the secondary data connection.

17.    Click OK to close all dialogs.

Finally, we need to manually modify the xpath of the destination to make sure we are only copying into the node we just inserted.

18.    In InfoPath, click File > Save As Source Files and choose a destination folder in your local drive.

19.    Navigate to that folder and open manifest.xsf in a text editor.

20.    Locate the node <xsf:ruleSets> towards the end of the file. This node contains your form’s rules.

21.    Find the second rule we created. In the case of our sample form, it looks like this <xsf:assignmentAction targetField="xdXDocument:get-DOM()/my:myFields/my:group1/my:group2/my:field1" expression="."></xsf:assignmentAction>

22.    Change the rule to add [last()], as seen here: <xsf:assignmentAction targetField="xdXDocument:get-DOM()/my:myFields/my:group1/my:group2/my:field1[last()]" expression="."></xsf:assignmentAction>

Resave the form and test:

23.    Save manifest.xsf.

24.    Right-click on the manifest and select Design.

Double-click on the button and then click Rules to verify your rules. This is what your rules will look like once you are done:

 

Optionally, select the second action and click Modify. Verify that the xpath to the target field is underlined; this visual cue indicates that InfoPath has recognized our manual modification.

Now you can preview the form and test it! Click on copy over for John Doe and that value gets inserted into the destination table.

 

Click on copy over for Bruce Wayne and that value gets inserted into the destination table.

 

Published Aug 04 2009, 09:01 AM by ErnestoM
Filed under:

Comments

No Comments
Copyright © 2003-2010 Qdabra Software. All rights reserved.
View our Terms of Use.