Use Runtime entities in business rules

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business Rules examples > Cases and activities >

Use Runtime entities in business rules

Overview

Runtime entities contain read-only information relating Bizagi’s process and cases internal data. Runtime entities are created by default in each project; you may not create additional entities nor add or modify their attributes.

 

The information of Runtime entities is available to be easily exposed for business rules, to be used exclusively within Process activities.

Since Runtime entities require the context of a case to retrieve information, they are not available in global objects such as Entity rules nor Library rules.

 

The starting point of Xpath navigation is <Case>, to reach attributes and collections available. Navigation of these entities work just like the Xpaths in the process entity.

 

Considerations

Attributes from Runtime entities are read-only, and are presented at the same level as the Process entity when opening the data model. If a business rule tries to write values over any of them, an error message will be presented at Runtime.

The navigation through Xpath for all Runtime entities and their attributes is done from its  root entity <Case>

All collections return a Bizagi array list. They can be filtered and navigated to obtain the data required.

Xpath functions are supported. For example <max()>, <count()>, <min)>, and so on.

Runtime entities that return collections can be used with the entity-list function: Me.getXPath("entity-list('CaseInfo','')");

Below an example is given where the same outcome is obtained by using regular Xpaths or entity-list.

Because of their nature Me.setXPath, CHelper.setAttrib, and setting values directly through Xpath is not supported. These entities are read-only.

The Xpath funcitions that change collections cannot be used, as they change the structure of the entities. Functions such as attachCollectionItem, deleteAllCollectionItem, detachAllCollectionItem and newCollectionItem.

The function CHelper.getEntityAttrib does not support Runtime entities's collections

 

Building Runtime entities Xpaths

Considering their data model presented below, the Case entity which is the main entity to use for navigation is depicted in blue. One-to-many relationships are red and many-to-many relationships are green.

We can build Xpaths as follows:

 

Simple Xpaths

 

Case number: <Case.CaseNumber>

 

Process display name: <Case.ProcessDisplayName>

 

Creator user's full name: <Case.CreatorUser.fullName>

As Creator user is related to WFUser table, all the WFUser attributes are available through Xpath, such as email, delegate, language, boss, and so on.

 

Collection Xpaths

 

Name of all activities created in the process: <Case.Activities.ActivityName>

This information is returned in the form of a Bizagi array list.

An example of the returned array could be: [Request vacation leave, Approve request]

 

Full name of all the performers of the case: <Case.Activities.Performer.fullName>

This information is returned in the form of a Bizagi array list.

An example of the returned array could be: [John Doe, Sarah Brown]

 

Types of allocations that the case has gone through: <Case.Activities.PerformerHistory.AllocationType>

This information is returned in the form of a Bizagi array list, with the allocation type per activity. Thus each activity is registered more than once.

An example of the returned array could be: [Candidate, BestCandidate,Assignee, Candidate, BestCandidate, Assignee]

 

The list of Performers, considering each type of Allocation type: <Case.Activities.PerformerHistory.IdAllocationPerformer.fullName>

This information is returned in the form of a Bizagi array list, with repeated names, given the structure of the entity.

The returned array could be: [John Doe, John Doe,John Doe,Sarah Brown,Sarah Brown,Sarah Brown]

 

BusinessRulesexamples28

 

 

RuntimeEntities1

 

 

Example

For illustration purposes, the following example displays two ways in which the same information can be retrieved.

Both options return the same information: the status that a case has gone through.

 

BusinessRulesexamples29

 

Navigating through entity-list

var parameters = new FilterParameters();

parameters.AddParameter("@idcase", Me.Case.Id);

var BizagiArrayListObject = Me.getXPath("entity-list('BA_CaseStatusHistory','IdCase =@idcase')");

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

 var RowObject = BizagiArrayListObject.get(i);

 var Value = RowObject.getXPath("CaseStatus");

}

 

Navigating using Xpath

var Cases = <Case.CaseStatusHistory.CaseStatus>;

for (var j = 0; j < Cases.size(); j++){

 var RowObject2 = Cases.get(j);

}

 

 

Example 2

The following code obtains the current Task name, relying on the Runtime entities:

var idworkitem = Me.Id;

var CurrentActivity = Me.getXPath("Case.Activities[IdActivity=" + idworkitem + "]");

CurrentActivity.getXPath("ActivityName");

 

 

Example 3

The following code obtaining the identifier of the first user allocated to the current task, relying on the Runtime entities:

var idworkitem = Me.Id;

var CurrentActivity = Me.getXPath("Case.Activities[IdActivity=" + idworkitem + "]");

var user = CurrentActivity.getXPath("Performer").get(0);

user.getXPath("idUser");