Question
· May 4, 2016

Router custom message base on List property using Business Rules

Hello,

I am trying to router a custom message using the content of one of its property, but this property is a List. ¿How I can do it?

The rule could be something like this

<rule name="">
  <constraint name="msgClass" value="Test.TestMessage"></constraint>
    <when condition="Document.myList.GetAt(1).property1=&quot;AA&quot;">
      <send transform="" target="DummyOperation"></send>
      <return></return>
    </when>
</rule>

But this rule doesn't compile.

TestClass is a simple Request Class like this:

Class Test.TestMessage Extends Ens.Request
{
Property myList As %ListOfObjects;
}

¿Any help?

Discussion (6)1
Log in or sign up to continue

ERROR <Ens>ErrParsingExpression: Error al analizar la expresión 'Document.myList.GetAt(1)="AA"': ERROR <Ens>ErrInvalidToken: Token no válido en el desplazamiento 22
  > ERROR #5490: Error $ZE='HCIS.Rules.Test:evaluateRuleDefinition' al ejecutar el generador del método '%2'.
    > ERROR #5030: Se produjo un error mientras se compilaba la clase HCIS.Rules.Test

Hi David, 

The type %ListOfObjects implements GetAt (), not Get () to return an object from the list.

Also, this will return an object. I would have expected you to need to specify the property of the returned object, for the condition 

Something that will eventually look like

...   condition='Document.myList. GetAt(1).myProperty=&quot;AA&quot;'

Steve

Well, you can't write conditions in this way, and compile error which you see, it is actually parsing error for such condition
How you can change it, You should define some function which may do all this check or partially, just return some value for check.

To define such function, you should have your child for Ens.Rule.FunctionSet class, something like this

Class Test.Utils Extends Ens.Rule.FunctionSet
{

ClassMethod GetAt(value As %String = "", index As %String) As %String
{
    if $isobject(value) {
        quit value.GetAt(index)
    }
    quit ""
}

}

and then, you can use it in this way, where GetAt your just created function.

<rule name="">
<constraint name="msgClass" value="Test.TestMessage"></constraint>
<when condition="GetAt(Document.myList,1)=&quot;AA&quot;">
<send transform="" target="DummyOperation"></send>
<return></return>
</when>
</rule>

But your function should return final value for checking, and you can't use write so,

GetAt(Document.myList,1).property1=&quot;AA&quot;