Querying XML-based information in cases (with scopes)

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business rules examples > XML Helper object >

Querying XML-based information in cases (with scopes)


The XML Helper object is part of Bizagi's business rules API, and it provides data access for your processes when working with XML-structured information, as described at XML Helper object.

This section illustrates an example on how to use one of the methods featured by this object, the getCaseAsString method, which is oriented to querying information in any case, while relying on what is stored in its scope.



In the following sample process, assume we have a process entity called SimplePurchaseRequest.

Such process uses the following data model:





Therefore and in order to obtain information which has already been inputted for a case of this process, in an XML-compliant structure, you may rely on the CEntityXmlHelper.getCaseAsString method and obtain an string with all such information within.

Do this inside of an expression box, in a Bizagi business rule:





The overall expression shown in the image above is coded with the following:

var app_schema = CHelper.getXSD("App", "SimplePurchaseRequest");


var app_result = CEntityXmlHelper.getCaseAsString(Me.Case.Id, app_schema, null, "");



Consider that the CEntityXmlHelper.getCaseAsString method receives 4 inputs:

The first one which is the case identifier.

Note that you may use Me.Case.Id if you need information from the same case where you are executing the expression, but you may also retrieve information from a different case by ensuring you have its ID stored in a data model attribute.

The second one named app_schema in the example above, which is an XSD definition in a string, defining the fields you want to get for those applicable records.

Note that you will need to make sure you use an schema for the process entity of the process to which you have an instance's case ID.




How to use an XSD schema is described in the section below.

The third one is an XSL (or XSLT) definition in a string (i.e an XML transformation file), defining how you want to transform the output so that it has different information (filtered) or different naming in its structure. This input is entirely optional and not depicted in the example below but detailed in a section at the end of this article.

The fouth one is an XPath Context definition in a string, defining where Bizagi will start to interpret the schema. This input is entirely optional and not depicted in the example below but detailed in a section at the end of this article.

Similarly, the CEntityXmlHelper.getCaseAsString method will return an XML-structured string with the information of the given case, as presented below for this specific example:




The sample response, as shown above, is:

<?xml version="1.0" encoding="UTF-8"?>

<SimplePurchaseRequest key="852">


  <Requester entityName="WFUSER" key="6">


     <fullName>Tom Hall</fullName>





  <Requestedproduct entityName="Requestedproduct" key="3">


     <Name>Translation services</Name>






     <Vendors key="1">


        <Vendor entityName="Vendor" key="1">





     <Vendors key="2">


        <Vendor entityName="Vendor" key="3">





     <Vendors key="3">


        <Vendor entityName="Vendor" key="4">





     <Vendors key="4">


        <Vendor entityName="Vendor" key="2">









Obtaining information which is stored in Bizagi's scopes means that you will also get information that has not been persisted by the completion of an activity (is not visible from other points of the processes other than the actual activity).


CHelper.trace() and CHelper.getXSD()

Notice in the example above, that though two other methods are being used optionally (both CHelper.trace and CHelper.getXSD) these will often can be used together with CEntityXmlHelper.getCaseAsString for other purposes:

CHelper.trace: Allows you to print out custom traces of values and responses in the execution of the rules.

The image below shows what the sample expression prints out:




For more information about the use of this tracing option, refer to Validating business rules.


CHelper.getXSD: Allows you to obtain a predefined schema for any entity, as configured in Bizagi Studio.

The image below shows the registered schema for the main process entity (SimplePurchaseRequest), explicitly named as SimplePurchaseRequest as well (as referenced in the sample expression):




For more information about predefining schemas, refer to Bizagi's data model XML schemas.



Often, obtaining information from a case in an XML-structured string will allow you to use it for different requirements such as creating new cases based on other closed ones, or using that information to trigger a business event (i.e, set event) among others.


Using transformation files (XSL)

Consider the same example shown above, however this time, you may have the CEntityXmlHelper.getCaseAsString method apply an XLS transformation for you, so that the returned output has a different structure (i.e., possibly to have fewer information and formatted with different markup definitions such as HTML tags or any others). In this example we'll be adding an XPath Context parameter to let Bizagi know we are aiming to use SimplePurchaseRequest as the starting point of our schema.


The same example will be using now the third input parameter which is the following transformation file:




Notice this sample transformation file will only make use of the information at Requestdate and the Code of the Requestedproduct, while renaming the tags for such detail:

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

 <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" />

 <xsl:template match="/">

 <xsl:for-each select = "SimplePurchaseRequest">


                 <xsl:for-each select = "Requestdate">

                         <Requested><xsl:value-of select = "."/></Requested>


                 <xsl:for-each select = "Requestedproduct/Code">

                         <Product><xsl:value-of select = "."/></Product>







This means that the rule now looks like this:




With the code of the expression shown in the image above having:

var processentity_schema = CHelper.getXSD("SimplePurchaseRequest", "SimplePurchaseRequest");
var processentity_xsl = '<?xml version="1.0" encoding="utf-8"?>'
+ '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'
+ '<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" /><xsl:template match="/">'
+ '<xsl:for-each select = "SimplePurchaseRequest"><Root><xsl:for-each select = "Requestdate"><Requested>'
+ '<xsl:value-of select = "."/></Requested></xsl:for-each><xsl:for-each select = "Requestedproduct/Code">'
+ '<Product><xsl:value-of select = "."/></Product></xsl:for-each></Root></xsl:for-each></xsl:template></xsl:stylesheet>';
var processentity_result =
CEntityXmlHelper.getCaseAsString(Me.Case.Id, processentity_schema, processentity_xsl, "SimplePurchaseRequest");
CHelper.trace("my_trace", processentity_result);


Therefore, this method using such transformation file yields the following output: