Xpath Functions: Average Empty Count
From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS
<keywords content="keywords">average, empty, count, records, not exist, function, Avg</keywords>
Contents |
XPath functions
Examples in this article will use the following syntax. In the data model the Process Entity is: ProcessEntity.
This entity can be related with other entities until reaching a one-to-many relationship.
<ProcessEntityAttribute.….AttributeN.FactName[Filter]>
- ProcessEntityAttribute.….AttributeN: the Xpath starting with the Process Entity, until reaching the one-to-many entity.
- FactName: Name of the one-to-many relationship. This entity has a collection of records.
- Filter: Condition to be met in the collection.
- AttributeName: Name of the attribute in the 'many' entity, which should be a numeric attribute.
Examples are based in this data model.
This is a Credit Request Process. Each Request has a Client, and will need co-signers (more than one) to be approved.
A Request can have several products (can have more than one product with the same product type), and these products can be approved or rejected (Product State).
Avg (Average)
This function can only be used on collections that return values of numeric attributes (whole numbers, decimals or currency).
When you use this function, you get the average value of the entries existing in the collection.
<avg(ProcessEntityAttribute.….AttributeN.FactName.AtributeName)>
AttributeName: Name of the attribute in the N entity, which should be a numeric attribute.
Example: Let’s get the average value of the Loans Requested
<avg(Request.Products.ValueRequested)>
To get the average value of the entries that meet a condition, without using variables in the condition.
<avg(ProcessEntityAttribute.….AttributeN.FactName[Filter].AtributeName)>
Filter: Condition to be met
AttributeName: Name of the attribute in the N entity, which should be a numeric attribute.
Example:Obtain the average value of the Products that Require Disbursement.
<avg(Request.Products[RequireDisbursement=true] .ValueRequested)>
To get the average of the entries that meet a condition, using variables.
Me.getXPath(“avg(ProcessEntityAttribute.….AttributeN.FactName[FilterVble].AtributeName)”)
FilterVble: Condition to be met using variables.
AttributeName: Name of the attribute in the N entity, which should be a numeric attribute.
Example: Get the average of the Products Requested whose Type is a variable, using the category code. var ProdType = 'CreditCard';
'Me.getXPath("avg('Request.Products[ProductType.Code = " + x + "].ValueRequested)")
Example: At the Ideal Bank, a special study is being conducted on the payment capacity of co-signers. In the study, the average value of the Co-signer’s income and expenses are used. To calculate the payment capacity, a library rule was used to receive total income and total expenses as parameters. Let’s see how you would get the average value of the income and expenses.
Modifying the above example, now you have to create the rule that will average the total income and expenses of the Viable co-signers. This would require filtering the expression.
Count
When you use this function, you get the total number of entries in the collection.
<count(ProcessEntityAttribute.….AttributeN.FactName)>
Example: Get the total number of Products and assign the value to the field NumberOfProducts:
To get the number of entries that meet a condition, without using variables in the condition.
<count(ProcessEntityAttribute.….AttributeN.FactName[Filter])>
Filter: Condition to be met
Example: Get the total number of Approved Loans Requested.
<count(Request.Products[ProductState.State= 'Approved')>
To get the number of entries that meet a condition, using variables in the condition.
Me.getXPath(“count(ProcessEntityAttribute.….AttributeN.FactName[FilterVble])”)
FilterVble: Condition to be met using variables.
Example: Get the number of Approved Products Requested. Assume Status for Approved is saved in a variable. var x = 'Approved';
Me.getXPath("count(Request.Products[ProductState.State= " + x + "])")
Example: Within the Consumer Loan Request Process, when all the products of the Request are rejected, an activity is generated for the commercial advisor where he/she must inform the Client of the grounds for Rejection.
The complete expression presented above reads:
<count(Request.Products[ProductState.State='Rejected'])>== <count(Request.Products)>;
Empty
When you use this function, you get true when the collection has no entries.
<empty(ProcessEntityAttribute.….AttributeN.FactName)>
Example: Find out whether or not there are any Products Requested
<empty(Request.Products)>
To verify whether or not there are any entries that meet a condition, without using variables in the condition.
<empty(ProcessEntityAttribute.….AttributeN.FactName[Filter])>
Filter: Condition to be met
AttributeName: Name of the attribute in the N entity, which should be a numeric attribute.
Example: Let’s verify whether or not there are any Approved Loans Requested.
<empty(Request.Products[ProductState.State= 'Approved'])>
To verify whether or not there are any entries that meet a condition, using variables in the condition
Me.getXPath(“empty(ProcessEntityAttribute.….AttributeN.FactName[FilterVble])”)
FilterVble: Condition to be met using variables.
Example: Verify whether or not there are any Approved Products. Status for Approved is saved in a variable.
var x = 'Approved';
Me.getXPath("empty(Request.Products[ProductState.State = " + x + "])")
Example: When the Loan Request DOES NOT have any associated guarantees, the process should NOT enter the Constitution process.
Modifying the above example, considering that some guarantees require constitution and others do not. When the Credit Request has no guarantees that require constitution associated with it, the process should not enter the Constitution process.
The complete expression presented above reads:
<empty(Request.Guarantees[RequiresConst=true])>
<comments />