IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Developing monitor models > Create monitor models

Tips and techniques for writing expressions

Use the following tips and techniques when writing XML Path Language (XPath) expressions for metric and outbound event values, trigger conditions, inbound event filters, and so on.


If statement considerations

If you are getting an error when using an if statement, you might be required to specify an else clause.

For example, you might use this command:

if (myMetric eq 'abc') then 100 else 0


Setting the value of a metric

You can use an if statement in the expression to set the value of the metric:
if (inboundEvent_field eq 'sometext') then 100 else 0


Dividing in XPath

The following example shows how to perform division:
 myNumericMetric div 5
Division can be used with numeric types (xs:integer or xs:decimal) as well as xs:duration (to divide a duration by a number or by another duration).

To protect against dividing by zero, which causes an exception, wrap the expression in a condition that makes sure the divisor is not zero before performing the calculation.

For example, do not write:

StockTradeBPEL.BR.HT.InvalidTrades div StockTradeBPEL.BR.HT.TotalTrades
Instead, write:
if (StockTradeBPEL.BR.HT.TotalTrades ne 0) then StockTradeBPEL.BR.HT.InvalidTrades div StockTradeBPEL.BR.HT.TotalTrades else 0


Aggregating a metric

If you have a measure that is aggregating a metric, you can ignore a metric in the aggregation by using null values in the metric.

If you want to purposefully ignore the metric in the aggregation until some condition is met, follow these steps:

  1. Set a default value for the metric so that it is null when the monitoring context instance is created.

  2. Use the following expression to set the value of the metric if a condition is met. If the condition is not met, the value will remain null.
    if (myMetric eq 'abc') then xs:decimal(100) else ()


Use the minimum aggregation function with a stopwatch

Setting the aggregation function to minimum for a stopwatch might give the wrong results, because the default value for a stopwatch is 0, not null. All instances are included in the aggregation, even those where the stopwatch never starts, so the minimum might always be 0.

Instead of using the stopwatch directly, define a duration metric that copies the value of the stopwatch. Use a trigger to define when the value is copied. You could define a trigger that fires when any event comes in, or you might be able to use an existing trigger in your model.

Do not define a default for the metric. Define the following metric value expression:

if ( StopwatchA ne xs:dayTimeDuration( 'PT0S' ) ) then StopwatchA else MetricB
where StopwatchA is the stopwatch and MetricB is the metric. You can now apply the minimum aggregation function to MetricB.


Calculating a duration metric

The following example shows how to calculate a duration metric using time stamp metrics:
Order_End_Time - Order_Start_Time


Converting a duration metric to days

The following example shows how you can convert a duration metric to the number of days represented by the duration:
xs:string(Average_Process_Duration_KPI div xs:dayTimeDuration('P1D'))


Comparing a duration metric to a constant value

You can compare a duration metric to a constant value. In the following example, the duration is 3 days, 1 hour.
Average_Process_Duration ge dayTimeDuration('P3DT1H')


Adding references to elements

Fields in a monitoring context (such as metrics, counters, and stopwatches) and attributes of inbound or outbound events are referenced by their IDs. If the referenced fields are in parent or child monitoring contexts, their IDs are used as part of the navigation path, as in the following examples:

Reference examples
Referenced Field Description
orderTotal A metric with an ID of orderTotal in the current monitoring context
timeSinceProcessStart A stopwatch with an ID of timeSinceProcessStart in the current monitoring context
itemContext/itemCost A metric with an ID of itemCost in a child monitoring context with an ID of itemContext
../orderNumber A metric with an ID of orderNumber in the parent monitoring context
delayNotification/predefinedData/severity A predefined data element in a Common Base Event that is received or sent through an inbound or outbound event definition with an ID of delayNotification
delayNotification/extendedData/orderValue An extended data element in the inbound or outbound Common Base Event
delayNotification/propertyData/cause A context data element in the inbound or outbound Common Base Event
Submit_Claim/createClaimResponse/app:claim/app:claimItem[@type="ACCIDENT"]/app:amount An attribute in an inbound event that has an XML Schema Definition (XSD)-based event part

All but the last path expression previously shown are relative (start with an ID) and navigate from the monitoring context in which the expression containing this reference is evaluated.

Create monitor models