Obtain and use Entity values

<< Click to Display Table of Contents >>

Navigation:  Low-code Process Automation > Studio Cloud - Authoring environment > Bizagi Studio > Process wizard > Business Rules > Business Rules examples > Collections and entities >

Obtain and use Entity values

Modify specific attributes from specific records of an entity not related to the Data Model

When updating attributes not related to the data model, while using Me.getXPath("entity-list"), you must create an scope attribute in the Process entity. This will allow you to temporarily save the ith record of the entity-list, and then, update it.

 

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.

 

Include a expression as an activity action.

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

 

CHelper94

 

We have created a Scope attribute in the process, called kmCreditRequestTemp. We will use it to store the ith value of each request.

Then,  update the attribute that identifies is a request is penalized at each request.

 

 

Entity-List

 

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

{

//Use the Scope attribute to store the ith record, then update the penalized request

 <CustomersFollowUp.kmCreditRequestTemp> = ListOfRequests[i].getXPath("Id");

 <CustomersFollowUp.kmCreditRequestTemp.RequestPenalized> = true;

}            

 

 

 

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","filterExpresion",filterParameters)

 

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.

 

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

 

//Create the set of filter parameters

var parameters = new FilterParameters();

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

parameters.AddParameter("@RiskValue",<CreditRequest.Risk>);

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

 

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 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");

 

 


Last Updated 9/13/2023 9:19:29 AM