Obtain and use Entity values

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business Rules examples > Collections and entities >

Obtain and use Entity values

Get a value from an Entity not related to the Data Model

Suppose in a Credit Request process the maximum amount that can be requested is based on a risk assessment. When an Analyst enters a calculated risk score in the Payment Capacity Task and clicks Save, the upper limit approval amount must be displayed.


The estimates of risk are stored in a Parameter Entity where each range has a corresponding maximum amount as follows:




Since the Parameter Entity Risk is not directly related to the Data Model, we need to use a function that searches with given criteria and returns a value.

We will use the getEntityAttrib function. This function can be found in the Data Navigation category.

It will pass the risk score entered by the Analyst, determine the range set and return the maximum amount that can be requested.  




The syntax of the function is:




The entity is the Parameter Entity Risk.

The value to return is the Maximum Approved Amount

The filter expression is the general range of the risk entered.

The filter parameters are the values of the range filtered in the filter expression


To perform this calculation, go to the fourth step of the Bizagi Process Wizard and select Activity Actions.

Click the Task where the upper limit approval amount must be displayed and create an On Save Expression.




The risk score entered by the Analyst is stored in the attribute Risk.

The maximum amount will be assigned to the attribute MaximumAmount.




The expression would be as follows:




//Create the set of filter parameters

var parameters = new FilterParameters();

//Set as a parameter the maximum approved amount related. Parameters names MUST start with @


//Obtain the entered risk score

<CreditRequest.MaximumAmount>=CHelper.getEntityAttrib("Risk","MaximumApprovedAmount","(LowerBound<=@RiskValue) AND (UpperBound>@RiskValue)",parameters);


Click OK to save the changes.


When the Analyst enters a risk score and clicks Save,  the corresponding maximum amount is displayed.






Get values from a Collection

Suppose in a Purchase Request process you have a collection of Products in which each product has a unit price and a quantity. The requirement is to obtain the total cost of the products on order.


We need to iterate over the Product's collection returned by an XPath query. For each product we will obtain the total price and add it to a total purchase cost.


To iterate over the collection, we need to store the XPath query in a variable and call the GetValueAsCollection function passing the query variable as a parameter.  Once the value has been converted to an array list, you can go through the values of the collection by iterating with a FOR function.



You can perform this example using the Iterate Over XPath function. This example is for illustration purposes.




The function GetValueAsCollection can be found in the Data Navigation category.




The syntax of the function is:




The parameter of this function is the XPath to the collection to be obtained, in this case it will be the collection XPath Products Requested.


Create an expression On Save of the Task where the calculation will be performed.




Add an expression and type the next code:




//Get the collection XPath in the variable Collection

var Collection=<PurchaseRequest.ProductsRequested>;

//Convert the Collection object to a collection to be iterated

var Array=CHelper.GetValueAsCollection(Collection);

//Initialize Variable to store the Total Cost

var Total=0


//Iterate the collection to go through each record and obtain each product price

for (var I=0; I < Array.size(); I++)


//Obtain each element and for each one the price and quantity

var Element= Array.get(I);

var ElementPrice=Element.getXPath("UnitPrice") ;

var ElementQuantity=Element.getXPath("Quantity");


//Accumulate the product price in a Total Cost variable



//Assign Total Cost to the attribute to be displayed



This is how the collection displays in the Work Portal




Once the expression is executed, the Total Cost is shown.




Obtain a specific attribute's values from a specific record of an entity

Suppose in a Contact Center a notification is sent when the time to respond the request expires. The notification is addressed to the boss of the person who is assisting a request. You need to obtain the email of the boss.


To do so you can use the CHelper.getAttrib function. This function returns the value of a given attribute of a specific record in an entity.


The parameters of this function are:


sEntityName: Name of the entity.

oEntitYKey: Id of the specific record within the entity.

sAttribName: Name of the entity attribute.


And the correct syntax is:


CHelper.getAttrib(sEntityName, oEntityKey, sAttribName);


Include an expression as an activity action.

Obtain the id of the current assignee boss using the Me.Case.WorkingCredential.UserProperties[] function




Use the CHelper.getattrib() function to obtain the email of the desired user from the WFUser entity. In this case store this value in an attribute of the data model (BossEmail).




//Obtain the identifier of the current assignee user

var BossId=Me.Case.WorkingCredential.UserProperties["idbossuser"];

//Obtain the email of the user from the WFUser entity

<ContactCenter.BossEmail> = CHelper.getAttrib("WFUser",BossId,"Email");


Modify specific attributes values from specific records of an entity

A bank offers multiple credit products to its customers. Once a product is approved and delivered, a monthly follow-up is performed  in order to evaluate if the customer has met the payments on time. In the case the customer defaults on the payments, all his/her requests in progress are penalized and will require further analysis in order to be approved.


To identify a request as penalized, a Boolean attribute in the data model is used. This attribute must be updated for all the customer's requests in progress, when he/she defaults on the payments.


To update this value you can make use of the CHelper.setAttrib function. This function assigns a value to a given attribute of a specific record in an entity.



The CHelper.setAttrib function must be used to update records retrieved using getXPath(“entity-list”).


The parameters of this function are:


sEntityName: Name of the entity.

oEntitYKey: Id of the specific record within the entity.

sAttribName: Name of the entity attribute.

oAttribValue: Value to be set.


And the correct syntax is:


CHelper.setAttrib(sEntityName ,oEntityKey, sAttribName, oAttribValue);


Include a expression as an activity action.

First obtain the list of in progress cases of the customer that will be penalized.




Then update the attribute that identifies is a request is penalized at each request. To do so navigate the list of requests and use the CHelper.setAttrib function.




//Obtain the list of cases of the user evaluated

var IdCustomerEvaluated=<CustomersFollowUp.CustomerEvaluated.Id>

var parameters = new FilterParameters();

parameters.AddParameter("@idRequester", IdCustomerEvaluated);
var ListOfRequests = Me.getXPath("entity-list('CreditRequest', 'idRequester=@idRequester')", parameters);


//Update each case

for (var i=0;i<ListOfRequests.size();i++)