Skip to content

Query

Performs an xquery on repository and returns the results as string array.

1
$XmlRepository.Query(xquery: string, parameters: object, collection: string):Array<string>

Parameters

string xquery
    Specifies the query to perform on the database.

object parameters
    Specifies the binding parameters on xquery string.

string collection
    Specifies the collection name to query. If not specified, the domain database will be queried.

Remarks

If query does not return any result than return value is empty array.
The examples below shows how to query the domain database.
The syntax of the query is quite detailed. More information can be found on xquery standard page. ,

Find all customers

1
2
var results = $XmlRepository.Query('//Customer');
$Xml.InnerXml( 'Customer', results.join() );

Find customer by id

1
2
3
4
var results = $XmlRepository.Query('//Customer[Id=$id]', {
id : $Xml.Evaluate('CustomerId')
 });
$Xml.InnerXml( 'Customers', results.join() );

Query Update

1
2
3
$XmlRepository.Query('for $customer in //Customer[Id=$id] return replace value of node $customer/Name with "Lady Gaga"', {
   id : $Xml.Evaluate('CustomerId')
});

Query Insert

1
2
3
4
$XmlRepository.Query('insert node (<Kaynak><Id>{$newId}</Id><Ad>{$newName}</Ad></Kaynak>) as last into /KVKEnvanter/Tanimlar/Kaynaklar', {
    newId: newId,
    newName: name.trim()
});

Query Delete

1
2
3
4
5
6
7
$XmlRepository.Query('let $nodeValue := fn:parse-xml-fragment($nodeValue)' +
                     'for $record in Relation[Id=$id]/RepHistory/RepHistoryRecord[InstanceId=$instanceId] return ' +
                     '(delete node $record)', {
   id : relationId,
   instanceId : $Xml.Evaluate('SelectedHistory/Id'),
   nodeValue : $Xml.SelectSingle('.').InnerXml()
});

Info

If you want to query the database of a process, you can use the collection keyword. You have to give the name of the database which is a GUID.

For process databases, you can have that GUID by $Instance.ProcessId.

Example

1
2
3
4
5
Querying process database
var results = $XmlRepository.Query('collection("49551ed3-6229-408a-aaaa-eb510463acad")//Customer[Id=$id]', {
   id : $Xml.Evaluate('CustomerId')
 });
$Xml.InnerXml( 'Customers', results[0].Evaluate('Id') );

See Also