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

Chapter 7 - Data connections and web requests

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 six commands work with the form's data connections and with web services that have no data connection at all: re-point a query or submit connection to another URL, read a connection's current URL, run your own SQL through an SQL connection, add a WHERE clause to an SQL query, and send an HTTP request. 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 and these data connections:

my:myFields
  my:SiteUrl
  my:CustomerId
  my:Region
  my:ResponseText
  my:SqlParams
    my:SqlParam            (repeating)
      my:Name
      my:Value
      my:Type
  my:Headers
    my:Header              (repeating)
      my:Name
      my:Value

Data connections:
  Customers        SQL query
  Settings         XML file (in the template)
  OrderService     web service
  SubmitToLibrary  SharePoint library submit
  Projects         SharePoint list query

Timing. A connection that is re-pointed must not run before the change. Connections with Query during form load switched on run before any rule (see Chapter 1), so switch that off on the connections you re-point. Run ChangeConnectionUrl and ChangeSubmitUrl from QdabraRules > finishedLoading, the first rules to run when the form opens, and put them before any rule that queries or submits. The FormsDesigner User Manual, Chapter 7 describes this start-up order in detail, including the Dynamic Data Connections XTP that runs these commands for you.

7.1 ChangeConnectionUrl

Changes the URL of a data connection at run time. Use it when a template moves between sites (for example from a development site to production) and its queries must follow the site the form is opened on.

Syntax

ChangeConnectionUrl /dsname=<data connection> /url=<URL> [/listguid=<GUID> | /listname=<list name>]
Parameter Required Description
/dsname Yes Name of the data connection, exactly as shown in the designer.
/url Yes The new URL. For a SharePoint list connection, the URL of the site that holds the list.
/listguid For SharePoint list connections, one of the two GUID of the list.
/listname For SharePoint list connections, one of the two Name of the list.

Result: the new URL.

Examples

ChangeConnectionUrl /dsname=OrderService /url=https://services.contoso.com/orders/OrderService.asmx
ChangeConnectionUrl /dsname=Projects /url-xpath=/my:myFields/my:SiteUrl /listname=Projects

The first re-points a web service connection. The second points a SharePoint list query at the site stored in SiteUrl, using the list named Projects on that site.

Notes

Related: ChangeSubmitUrl, GetConnectionUrl.

7.2 ChangeSubmitUrl

Changes the folder or library that a SharePoint library submit connection submits to. Use it to send forms to a different library, or to the same library on the site the form runs on.

Syntax

ChangeSubmitUrl /submit=<submit connection> /url=<library or folder URL>
Parameter Required Description
/submit Yes Name of the SharePoint library submit connection.
/url Yes The library or folder URL to submit to.

Result: the new URL.

Example

ChangeSubmitUrl /submit=SubmitToLibrary /url=https://contoso.sharepoint.com/sites/finance/ExpenseReports

Later submits through SubmitToLibrary save the form in the ExpenseReports library of the finance site.

Notes

Related: ChangeConnectionUrl, GetConnectionUrl.

7.3 GetConnectionUrl

Returns the URL a data connection currently uses. Use it to check what a connection points to, for example while testing a ChangeConnectionUrl rule, or to build another URL from it.

Syntax

GetConnectionUrl /dsname=<data connection>
Parameter Required Description
/dsname Yes Name of the data connection.

Result: the connection's current URL. Success is false if the connection type has no URL.

Example

GetConnectionUrl /dsname=OrderService /resultxpath=/my:myFields/my:SiteUrl

Writes the web service's current URL into SiteUrl.

Notes

Related: ChangeConnectionUrl, ChangeSubmitUrl.

7.4 ExecuteSqlQuery

Runs an SQL statement of your own through an existing SQL data connection, optionally with typed parameters taken from the form. Use it to call a stored procedure, or to run a query that the connection's own command cannot express.

Syntax

ExecuteSqlQuery /dsname=<SQL connection> /sql=<SQL> [/detectname=true] [/parametersxpath=<XPath> /parametersnamepath=<relative XPath> [/parametersvaluepath=<relative XPath>] [/parameterstypepath=<relative XPath>] [/parametersallownullpath=<relative XPath>] [/parametersdsname=<data source>]]
Parameter Required Description
/dsname Yes Name of the SQL data connection to use.
/sql Yes The SQL to run, for example EXEC Sales.dbo.GetCustomer @customerId = 12345.
/detectname No true uses the name of the queried table as the element name of the result rows. Default false: the data source's usual row names are used.
/parametersxpath No XPath to the nodes (usually rows) that describe the query parameters, one node per parameter.
/parametersdsname No Data source of /parametersxpath. Omit for the main data source.
/parametersnamepath With /parametersxpath Path, relative to each parameter node, to the parameter name.
/parametersvaluepath No Path, relative to each parameter node, to the value. Default . (the parameter node itself).
/parameterstypepath No Path, relative to each parameter node, to the data type: boolean, datetime, decimal, integer, string or innerxml (any case). Default string when the path is not given or the type field is empty.
/parametersallownullpath No Path, relative to each parameter node, to a field that says whether the parameter may be null. Default false when the path is not given, the field is missing or empty.

Result: empty on success. The returned rows go into the data source of the SQL connection, as with a normal query.

Examples

ExecuteSqlQuery /dsname=Customers /sql=SELECT * FROM dbo.Customers WHERE Region = 'West'
ExecuteSqlQuery /dsname=Customers /sql=EXEC dbo.GetCustomer @CustomerId /parametersxpath=/my:myFields/my:SqlParams/my:SqlParam /parametersnamepath=my:Name /parametersvaluepath=my:Value /parameterstypepath=my:Type

The first runs a fixed query. The second calls a stored procedure with one parameter per SqlParam row; with a row of Name @CustomerId, Value from the form and Type integer, the value is passed as a typed parameter instead of being pasted into the SQL text.

Notes

Related: ModifySqlQuery, CopyTable.

7.5 ModifySqlQuery

Appends text, usually a WHERE clause, to an SQL connection's existing query and runs it. Use it to filter an SQL query by values in the form without writing the whole statement.

Syntax

ModifySqlQuery /dsname=<SQL connection> /where=<SQL text> [/detectname=true]
Parameter Required Description
/dsname Yes Name of the SQL data connection.
/where Yes Text appended to the connection's query, including the keyword, for example WHERE Sales >= 12345.
/detectname No true uses the name of the queried table as the element name of the result rows. Default false.

Result: empty on success. The returned rows go into the data source of the SQL connection.

Examples

ModifySqlQuery /dsname=Customers /where=WHERE Region = 'West'
ModifySqlQuery /dsname=Customers /where-xpath=/my:myFields/my:Region

The first filters the Customers query to the West region. In the second, the Region field holds the complete clause (for example built with a Set a field value and concat()), passed in as it is.

Notes

Related: ExecuteSqlQuery.

7.6 MakeRequest

Sends an HTTP request (GET, POST, PUT or DELETE) and returns the response body. Use it to call a REST API or any URL that has no data connection in the template.

Syntax

MakeRequest /path=<URL> [/method=GET|POST|PUT|DELETE] [/content=<text>] [/contenttype=<MIME type>] [/username=<user>] [/password=<password>] [/headerspath=<XPath> /headernamepath=<relative XPath> /headervaluepath=<relative XPath> [/headersdsname=<data source>]] [/timeoutms=<n>]
Parameter Required Description
/path Yes The URL to send the request to.
/method No GET, POST, PUT or DELETE. Default POST when /content is given, GET when it is not.
/content No The request body.
/contenttype No Content type of the body. Default text/plain.
/username No User name for authentication.
/password No Password for authentication.
/headerspath No XPath to repeating rows that each hold one request header.
/headernamepath With /headerspath Path, relative to each header row, to the header name.
/headervaluepath With /headerspath Path, relative to each header row, to the header value.
/headersdsname No Data source of the header rows. Omit for the main data source.
/timeoutms No Time limit in milliseconds; the request is stopped if it takes longer.

Result: the response body. If the request fails, Success is false, Error holds the failure message and Result still holds the response body, if any, so you can read an error response from the service.

Examples

MakeRequest /path=https://api.contoso.com/customers/1001 /resultxpath=/my:myFields/my:ResponseText
MakeRequest /path=https://api.contoso.com/orders /content-xpath=/my:myFields/my:ResponseText /contenttype=application/json /headerspath=/my:myFields/my:Headers/my:Header /headernamepath=my:Name /headervaluepath=my:Value /timeoutms=30000

The first reads a customer record with GET and stores the response in ResponseText. The second posts the JSON text in ResponseText (POST because /content is given), with one header per Header row, and gives up after 30 seconds.

Notes

Related: ExecuteSqlQuery, GetConnectionUrl.

Back to the Command Index.

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