Filtering Xpath

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Data Access through XPath >

Filtering Xpath

Collections can be filtered to obtain a smaller set of values to be manipulated. Filters are a powerful tool that restrict the number of elements that are represented in an Xpath Expression.
A filter indicates one or more conditions to be met within a one-to-many (1:N) relationship. Filters are used in expressions to evaluate records of a collection.

These conditions are established in brackets after the relationship name which identifies the 1:N relationship.


<xpath[filter condition]>


The data model diagram below will be used as a guide to show how the structure of a filter uses Xpath.

Imagine a Purchase request Process whose data model is displayed below. A Purchase Request process has a Process Entity called Purchase Request.  The Process Entity has a one-to-many relationship with the entity called Products Requested for Purchase.


To obtain a collection of the requested products where the unit price is greater than 1000, use the expression:

<PurchaseRequest.ProductsRequestedforPurchase[UnitPrice > 1000]>


Every purchase request obtains many quotations to choose the best supplier. For this reason, there is a one-to-many relationship, named Quotation, between the Purchase Request and Quotation entities.


To obtain the selected quotations, use the expression:

<PurchaseRequest.Quotation[Selected = true]>


To obtain the supplier email address of each selected quote, use the expression:

<PurchaseRequest.Quotation[Selected = true].Supplier.Email>


When you navigate beyond a collection, as in the above example, the Xpath expression can either return a collection or merely a number depending on the number of records that meet the filtered condition.

Therefore the expression will return a collection of emails where more then one supplier was selected.


You can compose a number of conditions in a filter with the logical operators "AND" and "OR". Within the filter don't use parenthesis.
If parenthesis are needed you must use the function Me.getXPath("")

To obtain the Products requested that have a quotation related and where it is for more than 1000, we would include the "AND" operator:

<PurchaseRequest.ProductsRequestedforPurchase[QuotationsRequested = true AND UnitPrice > 1000]>





Understanding xpath2



You can use the following operators in filters:







<PurchaseRequest.Quotation[Selected = true]>


not equal

<PurchaseRequest.Quotation[Selected != true]>


greater than

<PurchaseRequest.ProductsRequestedforPurchase[TotalPrice > 1000]>


less than

<PurchaseRequest.ProductsRequestedforPurchase[UnitPrice < 1000]>


greater than or equal to

<PurchaseRequest.Quotation[QuotationDiscount >= 1000]>


less than or equal to

<PurchaseRequest.Quotation[DiscountPercentaje <= 0,1]>



<PurchaseRequest.Quotation[QuotationDiscount >= 1000 AND DiscountPercentaje <= 0.1]>



<PurchaseRequest.Quotation[QuotationDiscount >= 1000 OR DiscountPercentaje <= 0.1]>

is true  (default)



is false





Assign and obtain values with Xpath filtered collections

The easiest way to assign a value or collection to an element is using the "=" operator.


var quantity = <PurchaseRequest.ProductsRequested[QuotationRequested=true].Quantity>


In the variable, this Xpath expression stores a collection containing the amount of each quotation selected for every requested product related to a purchase.


<PurchaseRequest.Quotation[Discount >= true].Selected> = true

This expression will set the value of the Boolean attribute, Selected, to true for all the quotations that have a discount.