How to use Object Scripts within Ensemble Rule class Ens.Rule.Definition


I have a Rule Class which receives the HL7 message and sends it to the concerned target based on the condition.

Class XYZ Extends Ens.Rule.Definition [ CompileAfter = CUSTOM.Util.Rules.FunctionSet ]

Parameter RuleAssistClass = "EnsLib.HL7.MsgRouter.RuleAssist";

XData RuleDefinition [ XMLNamespace = "]
<ruleDefinition alias="" context="EnsLib.HL7.MsgRouter.RoutingEngine" production="ABCProduction">
<ruleSet name="" effectiveBegin="" effectiveEnd="">
<rule name="">
<when condition="(SearchOBXFlag(Document,&quot;searchvalue&quot;))">
<send transform="DTL.dtl" target="ToOperation"></send>




Condition uses return status of a function SearchOBXFlag from another class.

How do i  create a rule class to have an embedded  function which loops through an HL7 message and returns a value upon which i can route my message?

I dont want the SearchOBXFlag to exist in another ruleset class. Is there a option?


Jimmy Christian

  • 0
  • 0
  • 44
  • 3
  • 1


You can easily develop your own custom function. Here's an example of a custom function which checks that the number is valid.

/// Functions to use in rule definitions.
Class Custom.Functions Extends Ens.Rule.FunctionSet

/// Returns 1 if a string is a number, 0 otherwise
ClassMethod IsValidNumber(string As %String) As %Boolean [ CodeMode = expression, Final ]


Thank you Eduard. But i want to code this method  directly in my XYZ rule definition class instead of  coding in a seperate class with functions.

Reason is the Function set class is  shared by many projects and i do not want to modify or update it.

If you don't want to modify the existing class, write a new one that extends it:

/// Custom functions for this installation
Class User.Rule.MyFunctionSet Extends Ens.Rule.FunctionSet

/// Stupid, redundant method provided as an example
/// Accepts a string <var>pString</var> and regular expression pattern <var>pPattern</var>
/// as arguments; returns 0 for no match, and a positive integer indicating the match's
/// position if there is a match.
ClassMethod REMatch(pString As %String, pPattern As %String) As %Integer
    Return $LOCATE(pString,pPattern)


As long as you don't define a method that overrides a previous method, you're completely safe.

EDIT: Eduard's example beat me to it and does exactly the same thing. The point, though, is that you're not adding methods to the existing class, you're creating new methods outside of it that are accessible from within your rule definitions.

Thank you Jeffrey. Yep,  writing a new class and extending  Functionset class is totally fine.

But i am trying to find out if RuleDefinition class itself allows you to write any methods within it or you cannot embed a method within RuleDefinition class.