Chapter 2 - Values and nodes
These eight commands read and change the data in your form: set or read a field, add, copy, move or delete nodes, fill a repeating table from another table, and sort a table. They are the commands you will use most often. Chapter 1 explains the command syntax, dynamic parameter values and where results go; this chapter assumes you know it.
The examples use this main data source:
my:myFields
my:Status
my:Total
my:Expenses
my:Expense (repeating)
my:Date
my:Category
my:Amount
my:Approved
2.1 SetValue
Sets the value of one field, or of every field that an XPath selects. Use it instead of a plain Set a field value action when you need a filtered path in a repeating group, a field in another data source, or a nil value.
Syntax
SetValue /xpath=<XPath> [/dsname=<data source>] /value=<text> | /blank=true | /nil=true
| Parameter | Required | Description |
|---|---|---|
/xpath |
Yes | XPath to the field(s) to set. Every node it selects is set. |
/dsname |
No | Data source of the field. Omit for the main data source. |
/value |
One of the three | The new value. An explicitly empty /value= is allowed and clears the field. |
/blank |
One of the three | true sets the field to an empty value. Overrides /value. |
/nil |
One of the three | true empties the field and adds xsi:nil="true". Use it for date, number and other non-string fields, which are invalid when simply empty. Overrides /value. |
Result: empty on success.
Examples
SetValue /xpath=/my:myFields/my:Status /value=Approved
SetValue /xpath=/my:myFields/my:Expenses/my:Expense[my:Category='Travel']/my:Approved /value=true
SetValue /xpath=/my:myFields/my:Expenses/my:Expense/my:Date /nil=true
The second example sets Approved on every Travel row at once; the third clears every date in the table correctly.
Notes
- You must give one of
/value,/blankor/nil; otherwise the command fails with A value should be specified when not setting blank or nil. - If the XPath selects nothing, the command fails with Error: No nodes were found using the specified XPath. Nothing is changed.
- To take the new value from another field at run time, use
/value-xpath=(see Chapter 1).
2.2 GetValue
Reads a value and returns it in Result. It can also evaluate an XPath expression (count, sum, concat and so on), and in its multi-row form it writes a computed value into every row of a repeating group.
Syntax
GetValue /xpath=<XPath> [/dsname=<data source>] [/default=<text>]
GetValue /eval=true /xpath=<expression> [/xpathsrc=<XPath>]
GetValue /xpath=<XPath> /reldest=<relative XPath> [/append=true] (multi-row, copy)
GetValue /eval=true /xpathsrc=<rows> /xpath=<expression> /reldest=<relative XPath> (multi-row, compute)
| Parameter | Required | Description |
|---|---|---|
/xpath |
Yes, unless /xpathsrc is given |
The node to read, or with /eval=true the expression to evaluate. |
/dsname |
No | Data source. Omit for the main data source. |
/default |
No | Returned when the value is empty. |
/eval |
No | true evaluates /xpath as an expression and returns its string value. Default false. |
/xpathsrc |
With /eval and /reldest |
The nodes (usually rows) the expression is evaluated against. |
/reldest |
No | Turns on multi-row mode. XPath, relative to each source node, of the field that receives that node's value. |
/append |
No | With /reldest: true appends to the destination's current value instead of replacing it. |
/contextnode |
No | With /eval and /reldest: evaluate against this node instead of each source node. |
/xpathnode |
No | With /eval and /reldest: relative path to a field that holds the expression to evaluate. Takes precedence over /xpath. |
Result: the value (single mode), or the number of rows processed (multi-row mode).
Examples
GetValue /xpath=/my:myFields/my:Status /default=Draft
GetValue /eval=true /xpath=count(/my:myFields/my:Expenses/my:Expense)
GetValue /eval=true /xpath=sum(/my:myFields/my:Expenses/my:Expense/my:Amount)
GetValue /eval=true /xpathsrc=/my:myFields/my:Expenses/my:Expense /xpath=concat(my:Category, ': ', my:Amount) /reldest=my:Approved
The last example evaluates the expression once per expense row and writes each row's result into that row's own field.
Notes
/defaultcovers an empty field only. If the node does not exist at all, single mode fails with Failed to select field. The command description in the Command Builder says otherwise; the behavior above is what the engine does.- With
/eval=truethe expression is wrapped instring(), so the result is always text. A number comes back as, for example,1250orNaN. - In multi-row mode every source node must have the
/reldestfield, or the command fails with Failed to select the destination node. after updating the rows before it. /xpathnode,/contextnodeand/appendare only valid with/reldest.
Related: SetValue.
2.3 Copy
Copies nodes, with everything inside them, to a new place in the same or another data source. The source stays where it is.
Syntax
Copy /sourcepath=<XPath> /destpath=<XPath> [/sourceds=<data source>] [/destds=<data source>] [/location=lastChild|firstChild|before|after]
| Parameter | Required | Description |
|---|---|---|
/sourcepath |
Yes | The node(s) to copy. Every selected node is copied, in document order. |
/destpath |
Yes | The destination node. Only the first match is used. |
/sourceds |
No | Data source of the source. Omit for the main data source. |
/destds |
No | Data source of the destination. Omit for the main data source. |
/location |
No | Where to put the copies relative to the destination: lastChild (default), firstChild, before or after. Case-sensitive. |
Result: empty on success.
Examples
Copy /sourcepath=/my:myFields/my:Expenses/my:Expense[1] /destpath=/my:myFields/my:Expenses
Copy /sourcepath=/my:myFields/my:Expenses/my:Expense[my:Category='Travel'] /destpath=/my:myFields/my:Expenses/my:Expense[1] /location=before
The first example duplicates the first row at the end of the table, including its current values. The second copies every Travel row to the top of the table, keeping their order.
Notes
- When several nodes are copied, the first goes to
/locationand each following one is placed directly after the previous copy, so the original order is kept. - The copy keeps the source's element names. Copying a row from a secondary data source (for example a SharePoint or SQL query) into the main data source creates nodes with the secondary data source's names, which do not match your schema. Use CopyTable for that.
- Errors: Failed to select the source node., Failed to select the destination node., Invalid location value. Allowed values are firstChild, lastChild, before and after.
Related: Move, CopyTable, Insert.
2.4 Move
Works exactly like Copy, with the same parameters, but removes each source node after it has been placed. Use it to reorder rows or to move a group to another part of the form.
Syntax
Move /sourcepath=<XPath> /destpath=<XPath> [/sourceds=<data source>] [/destds=<data source>] [/location=lastChild|firstChild|before|after]
Result: empty on success.
Example
Move /sourcepath=/my:myFields/my:Expenses/my:Expense[last()] /destpath=/my:myFields/my:Expenses/my:Expense[1] /location=before
Moves the last row to the top.
Notes
- The source node is deleted right after its copy is inserted. If the deletion fails, the command stops with An error occurred trying to delete the node being moved. and the node exists in both places.
- Do not let
/destpathpoint inside the node you are moving.
2.5 Insert
Adds new, empty rows to a repeating group or table, in any view. Unlike Copy, the new row is built from the template's default data (the same row you get when a user clicks Insert item), not from an existing row.
Syntax
Insert /parent=<XPath> /child=<relative name> | /xpathsrc=<XPath> [/dsname=<data source>] [/posn=<n>|last] [/count=<n>] [/before=<relative XPath>] [/firstparentonly=true|false]
| Parameter | Required | Description |
|---|---|---|
/parent |
Yes | The group that holds the rows. |
/child |
One of the two | The row element, relative to /parent, without a leading slash (for example my:Expense). |
/xpathsrc |
One of the two | The full path of the row, used to find its default data. Needed when /parent contains a filter, such as [2]. |
/dsname |
No | Data source. Omit for the main data source. |
/posn |
No | last (default) appends. A number inserts before that row; 1 inserts at the top. A number larger than the row count appends. |
/count |
No | Number of rows to insert at each location. Default 1. |
/before |
No | Relative path from /parent to a sibling to insert before. Used only when /posn is last or omitted. If the sibling is not found, the row is appended. |
/firstparentonly |
No | Default true: if /parent matches several groups, insert into the first only. false inserts into all of them. |
Result: the number of rows inserted. Success is false if no row was inserted.
Examples
Insert /parent=/my:myFields/my:Expenses /child=my:Expense /count=3
Insert /parent=/my:myFields/my:Expenses /child=my:Expense /posn=1
The first adds three empty rows at the end; the second adds one at the top.
Nested tables: to add a receipt to the second expense only, the parent has a filter, so give the row's full unfiltered path in /xpathsrc:
Insert /parent=/my:myFields/my:Expenses/my:Expense[2]/my:Receipts /xpathsrc=/my:myFields/my:Expenses/my:Expense/my:Receipts/my:Receipt
Notes
- New rows carry the default values defined in the template. To fill them, follow Insert with SetValue, for example on
my:Expense[last()]. - Errors: You must include either /child or /xpathsrc., The child parameter value should not start with a slash., Failed to determine the node to insert. You may need to use /xpathsrc, Failed to select the parent node., Position must be "last" or a positive integer., Count must be a positive integer.
2.6 Delete
Deletes every node that an XPath selects: a field, a group, or rows of a repeating table.
Syntax
Delete /xpath=<XPath> [/dsname=<data source>]
| Parameter | Required | Description |
|---|---|---|
/xpath |
Yes | The node(s) to delete. Use a filter to pick rows. |
/dsname |
No | Data source. Omit for the main data source. |
Result: empty on success.
Examples
Delete /xpath=/my:myFields/my:Expenses/my:Expense[my:Amount='']
Delete /xpath=/my:myFields/my:Expenses/my:Expense[position() > 1]
The first removes rows with no amount; the second keeps only the first row.
Notes
- If nothing matches, the command reports Success
falsewith Could not locate field to delete. For a clean-up step that may find nothing (for example deleting blank rows), this is expected and can be ignored. - Deleting a required, non-repeating field makes the form data invalid. Delete rows and optional groups only.
2.7 CopyTable
Copies rows from one table to another, typically from a query data source (SharePoint list, SQL, web service) into a repeating table in the main data source. Each destination row is built from the template's default data and then filled from the matching source row.
Syntax
CopyTable /tablesrc=<XPath> /rowsrc=<relative XPath> /tabledest=<XPath> /rowdest=<relative XPath> [/dsnamesrc=<data source>] [/dsnamedest=<data source>] [/empty=true] [/xpathdest=<XPath>]
| Parameter | Required | Description |
|---|---|---|
/tablesrc |
Yes | The group that holds the source rows. Only the first match is used. |
/rowsrc |
Yes | The source rows, relative to /tablesrc. May include a filter. |
/tabledest |
Yes | The group that receives the rows. If it matches several groups, every one of them receives the rows. |
/rowdest |
Yes | The destination row element, relative to /tabledest. |
/dsnamesrc |
No | Data source of the source table. Omit for the main data source. |
/dsnamedest |
No | Data source of the destination table. Omit for the main data source. |
/empty |
No | true deletes the existing destination rows first, so the table is replaced instead of extended. |
/xpathdest |
No | Full unfiltered path of the destination row, used to find its default data. Needed when /tabledest contains a filter. |
Result: the number of rows copied.
Example
Fill the expense table from a SharePoint list query named ExpenseItems, replacing what is there:
CopyTable /dsnamesrc=ExpenseItems /tablesrc=/dfs:myFields/dfs:dataFields /rowsrc=d:SharePointListItem_RW /tabledest=/my:myFields/my:Expenses /rowdest=my:Expense /empty=true
Notes
- Fields are matched by position, not by name. The first field of the source row goes into the first field of the destination row, the second into the second, and so on. Attributes are matched the same way. Make the query return exactly the destination's fields, in the destination's order.
- Source and destination rows must have the same number of fields and attributes (
xsi:nilattributes are ignored), or the command fails with The table row of the source and destination must contain the same number of elements and attributes. - Rows must be flat: a row that contains a group fails with Copy Table does not work with tables containing groups. Rich text fields are fine. For nested data, use Insert and then SetValue.
- All rows are prepared before any is added, so an error part-way leaves the destination unchanged.
2.8 SortTable
Sorts the rows of a repeating table by one or more fields.
Syntax
SortTable /row=<XPath> /compare=<relative XPath>[,<relative XPath>...] [/order=asc|desc[,...]] [/type=text|number[,...]] [/dsname=<data source>]
| Parameter | Required | Description |
|---|---|---|
/row |
Yes | Full XPath to the rows to sort. |
/compare |
Yes | The field(s) to sort by, relative to the row. Separate several with commas; the first is the primary key. |
/order |
No | asc (default) or desc, one per compare field. |
/type |
No | text (default) or number, one per compare field. |
/dsname |
No | Data source. Omit for the main data source. |
Result: empty on success.
Examples
SortTable /row=/my:myFields/my:Expenses/my:Expense /compare=my:Amount /order=desc /type=number
SortTable /row=/my:myFields/my:Expenses/my:Expense /compare=my:Category,my:Date /order=asc,desc /type=text,text
The second sorts by category, and within a category by newest date first.
Notes
- With several compare fields, give
/orderand/typefor each one, even when they are the default./compare=a,balone fails with Parameter count mismatch for compare, order, and type parameters., because the defaults count as one value. - Because commas separate the fields, a compare XPath cannot itself contain a comma (for example
concat(a, b)). textcompares character by character: upper case sorts before lower case, and10sorts before9. Usenumberfor amounts. Dates stored asYYYY-MM-DDsort correctly astext.- With
number, empty or non-numeric values do not sort reliably. Fill them, or sort by text. - The rows' parent group is rewritten with the sorted rows. Keep the repeating rows alone in their group; any other field in the same group would be removed.
- A table with fewer than two rows is left as it is.
Related: Move.
Back to the Command Index.