How to use the SetValue command - Mel Balsamo
in

InfoPath Dev

This Blog

Syndication

Mel Balsamo

How to use the SetValue command

InfoPath allows us to set the value of a target field by using rules. We can even filter which field we want to set the value of. However, it can be a problem if that field happens to be in a repeating group.

The qRules SetValue command allows us to define the XPath to the target field. Using XPath filters with the SetValue command, setting a field’s value can be extremely easy when dealing with repeating data.

·         Arguments:

o    xpath: XPath to the field to set

o    value: New value for the field being set

·         Examples:

o    SetValue /xpath=/my:myFields/my:Group/my:RepeatingGroup/my:field2[../my:field1='abc'] /value=ABC

o    concat("SetValue /xpath=my:myFields/my:Group/my:RepeatingGroup/my:field2[../my:field1='", Filter, "'] /value=", Value)

This document assumes that you already have a qRules-injected form template. To demonstrate how the above examples work, design your form template based on the following guidelines/steps:

1.       Your main data source structure should be similar to this (all use a string data type):

2.       You have the following layout and controls on your canvas:

3.       In your ‘Set Value’ button properties, click on Rules.

4.       Add a rule that has an action that sets the value of your QdabraRules (Secondary) data source Command node:

to: SetValue /xpath=/my:myFields/my:Group/my:RepeatingGroup/my:field2[../my:field1='a'] /value=Test

 

5.       Preview your form template.

6.       Insert at least 5 items in your repeating table.

7.       In the Field 1 column, fill out some fields with the text ‘a’, and others with random texts, like shown:

8.       Click on the ‘Set Value’ button. You should get the result as shown:

 

In this example, we set our qRules Command to:

SetValue /xpath=/my:myFields/my:Group/my:RepeatingGroup/my:field2[../my:field1='a'] /value=Test

Using this command syntax, qRules will set the value of any row in the Field 2 column that has ‘a’ in Field 1. It sets the value of Field 2 to ‘Test’.

Like the other qRules command, you can also use a ‘concat’ statement if you wish to use specific fields with dynamic values in your parameters. For the next example, we’ll use the command syntax:

concat("SetValue /xpath=my:myFields/my:Group/my:RepeatingGroup/my:field2[../my:field1='", Filter, "'] /value=", Value)

9.       Back on your canvas in Design mode, change your button rule to set the value of the qRules Command node to the concat statement above. Note that since ‘concat’ is an InfoPath function, you will have to enter it as a formula, pointing Filter and Value to their respective nodes in the main data source:

10.    Preview your form template.

11.    Enter ‘John’ in the Filter text box and ‘John Smith’ in the Value text box.

12.    Insert at least 5 items in your repeating table, filling out some fields with the text ‘John’, and others with random texts, like shown:

13.    Click on the ‘Set Value’ button. You should get the result as shown:

When you’ve started using the SetValue command in your InfoPath solutions, you’ll see how helpful it is and how it can make dealing with repeating data easier.

Published May 28 2010, 12:26 AM by jose cruz
Filed under: , ,

Comments

No Comments

About jose cruz

Completed a degree in Electrical Engineering and worked as Software Test Engineer in several Telecommunications company in the US.
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.