Advanced filters

<< Click to Display Table of Contents >>

Navigation:  Low-code Process Automation > Studio Cloud - Authoring environment > Bizagi Studio > Process wizard > Business Rules > Bizagi Functions > Data Access through XPath >

Advanced filters

When collections have to be filtered using variables it is necessary to use setXPath and getXPath functions and NOT the angle brackets.

The following is the correct syntax for the XPath expression using variables:

 

To obtain values, use the syntax: Me.getXPath("XPath[filter " + variable +"]")

 

To set values, use the syntax: Me.setXPath("XPath[filter  " + variable +"]", value)

 

Me.setXPath

Suppose that you need to calculate the minimum percentage discount in the Quotation selection process.

Only quotations offering a discount higher than 10% of the total cost of the purchase will be selected.

You must declare a variable to store the calculation and then filter the collection to set only the selected records.

The expression should look like this:

 

var MinimumPercentage = <PurchaseRequest.TotalCost>* 0.1

 

Me.setXPath("PurchaseRequest.Quotations[QuotationDiscount > "+ MinimumPercentage +" ].Selected", true)

 

Me.getXPath

Select all the suppliers where no discount or a discount less than the 10% of the total cost of the purchase was given.

First declare a variable to store the calculation and then filter the collection to retrieve the records.

The expression should look like this:

 

var MinimumPercentage = <PurchaseRequest.TotalCost>* 0.1

 

var BadSuppliers = Me.getXPath("PurchaseRequest.Quotation[Discount != true OR QuotationDiscount < "+ MinimumPercentage +"]")

 

 

Understandingxpath2

 

Using XPath functions in Me.getXPath declarations

Given that the Me.getXPath function receives an XPath as a parameter, and that the XPath functions are treated as XPaths, you can use an XPath function inside a Me.getXPath declaration. To do so, follow the next syntax:

 

Me.getXPath("XPathFunction(collection[filter])")

 

Understandingxpath5

 

For example, if you want to obtain the average of the scores of the competencies that were selected, you could use the following expression:

 

Me.getXPath("avg(DevelopmentAssessment.CompetenciesCollection[isSelected = true])")

 

On the other hand, if your expression requires a filter which is defined in a variable, you should use the following syntax:

 

var variable = XVariable

Me.getXPath("XPathFunction(collection[filter'"+ XVariable +"'])")

 

For example, if you want to validate that there is at least one competency with a score greater that 4.5, use the following syntax

 

var minimumScore = 4.5

Me.getXPath("exists(DevelopmentAssessment.CompetenciesCollection[score>="+ minimumScore +"])")

 


Last Updated 1/6/2022 11:33:47 AM