Obtain and use Entity values

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business rules examples >

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:

 

CHelper38

 

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.

 

DataNavigation1

 

 

The syntax of the function is:

 

CHelper.getEntityAttrib("Entity","ValueToReturn","filter","")

 

The entity will be the Parameter Entity Risk.

The value to return will be the Maximum Approved Amount

The filter will be the range of the risk entered.

 

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.

 

CHelper39

 

 

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

The maximum amount will be assigned to the attribute MaximumAmount.

 

 

CHelper40

 

The expression would be as follows:

 

CHelper41

 

//Obtain the entered risk score

var RiskValue=<CreditRequest.Risk>;

// Obtain maximum approved amount related

<CreditRequest.MaximumAmount>=CHelper.getEntityAttrib("Risk","MaximumApprovedAmount",

"(LowerBound <="+RiskValue+") AND (UpperBound > "+RiskValue+")","");

 

Click OK to save the changes.

 

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

 

CHelper42

 

 

CHelper43

 

 

 

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.

 

note_pin

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

 

CHelper56

 

 

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

 

DataNavigation2

 

 

 

The syntax of the function is:

 

CHelper.GetValueAsCollection("Collection")

 

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.

 

CHelper52

 

Add an expression and type the next code:

 

CHelper53

 

//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

Total=Total+(ElementPrice*ElementQuantity);

}

//Assign Total Cost to the attribute to be displayed

<PurchaseRequest.TotalCost>=Total;

 

This is how the collection displays in the Work Portal

 

CHelper54

 

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

 

CHelper55

 

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

 

CHelper92

 

 

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).

 

CHelper93

 

 

//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 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.

 

 

CHelper94

 

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.

 

CHelper95

 

//Obtain the list of cases of the user evaluated

var IdCustomerEvaluated=<CustomersFollowUp.CustomerEvaluated.Id>

var ListOfRequests = CEntityManager.GetEntity("CreditRequest").GetEntityList("", "","idRequester="+IdCustomerEvaluated, "");

 

//Update each case

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

{

CHelper.setAttrib("CreditRequest",ListOfRequests[i].SurrogateKeyValue,"RequestPenalized",true);

}