Qdabra Forms - qRules Command Guide Every qRules command, its parameters and behavior All manuals

Chapter 2 - Values and nodes

First draft. This chapter has not been reviewed yet and may contain mistakes. Please read it with that in mind, and tell us about anything that does not match what you see.

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

Related: GetValue, Delete.

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

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

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

Related: Copy, SortTable.

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

Related: Copy, Delete.

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

Related: Insert, SetValue.

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

Related: Copy, Insert.

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

Related: Move.

Back to the Command Index.

© Qdabra Software  |  Questions and corrections: [email protected]  |  Preview copy, not linked from the public site.