Question
· Jul 15, 2020

Context Object visibility in Business Rule Custom Utility Function

Hi,

Business Rules can define a context object,  whose properties are exposed and used in the expressions of the rules. For example, my context object is an object with 3 properties. PropA, PropB and PropC.

When constructing my rules, I can call a custom function, and I have one I built myself called 'myFunction' which takes arguments and I pass in properties of my context object. (I can pass in the value of the context object's PropA, B or C).

But lets assume my context object was big, with many properties,  and serial objects and other references -  And, my custom function has needs many of these in order to get to a result.. .

An expression within the rule editor, calling myFunction, and many arguments needed to execute the function, can be quiet cumbersome, so, I want a way to pass the entire context object into myFunction - or - for myFunction() to have access to the entire context object of the rule.

Is this possible ?  Other than exposing the context object ID as its own property, and passing that yo my function, where it then re-opens the object - I couldn't think of any other approach. 

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

The first thought that came to me on this would be to define a class named MyContextClass which contains all of the many properties, collections, serial objects and so on and then define the Context Object to have one Property, 'Properties' whose data type is MyContextClass.

Then in the Business Rule you can use the syntax context.Properties.PropA and so on

Nigel

Hi Nigel.  

Not really. What I want to do is, in my Business Rule, call my custom function, passing the entire context object, not individual properties. Putting it out there again:

Assume I have a custom function called 'ValidateAllMandatoryFields' that returns a 1/0 from checking multiple properties of the context object and their inter-dependancies.

I'd like my rule to simply say:      IF ValidateAllMandatoryFields(<something>) ...
and for the function to see the whole context object, and do what it wants.

I don't want my rule to have to say:  IF ValidateAllMandatoryFields(context.Properties.PropA, context.Properties.PropB, etc.etc...)

Steve

Hi Nigel

Ok yes - that would work. When the context object is being populated with individual property values, - if the last thing I do is:

set myContextObject.context=myContextObject

then I can pass in the property 'context' into my function to gain access to the whole object. 

I could also just pass the rowID of myContextObject, and have myFunction re-instantiate it too.

I think this will have to be what I do, if the entire context object is not made public to my function.

Thanks - Steve

Cool, let me know if it works. I have a similar situation for a BPL I am intending to write and I know I will have the same issue you are trying to resolve so I will be keen to know if this approach works because it is something I have been thinking about in anticipation of writing my BPL. My BPL will have a call to a DTL and I want to pass my context object to the Business Rule and then pass it into the DTL as the 'aux' object which is the 3rd parameter in the Transform() method as in ##class(MyDTL).Transform(pRequest,.pResponse,aux)

This works fine in custom code in a Business Process as aux can be any instance of a class but if the DTL is invoked from a Business Rule the aux is a specific object instance that holds properties that tell you about the rule that invoked the DTL  and I'm not sure I can pass my context object into the Transform as AUX if the DTL is instantiating it's own AUX object

I guess if I seemlesly pass the context object into the DTL via a Business Rule then I'll just have to invoke the DTL as a line of custom code in the BPL rather than as a Business Rule.

Nigel