RulesEngine icon indicating copy to clipboard operation
RulesEngine copied to clipboard

ActionContext is not able to get the actual value assigned from the rules

Open vprabhu81 opened this issue 3 years ago • 6 comments

Hi,

Here is a snippet where we pass certain parameters on success and failure methods. image

Now I was expecting the underlying value in my action context but instead I get the value in string like "Device.Id". I tried a simple arithematic equation like "20*2" that too is being received as a string image

vprabhu81 avatar Sep 16 '22 10:09 vprabhu81

Hi @vprabhu81, this is intended behavior, context does not automatically get evaluated.

Can you provide the context on what you are trying to achieve?

abbasc52 avatar Sep 17 '22 05:09 abbasc52

I have these parameters passed into the rule engines, On success or failure I would need to retireve those data set to send notifications.

I am bit surprised though because I see that in the sample below we do pass the expressions as an input image https://microsoft.github.io/RulesEngine/#outputexpression

vprabhu81 avatar Sep 19 '22 05:09 vprabhu81

@abbasc52 : Just wanted to check with you if got a chance to look at the sample provided

vprabhu81 avatar Sep 21 '22 12:09 vprabhu81

Hi @vprabhu81 , assuming you want to create a custom action, context is passed as is and needs to be parsed at the custom action code e.g. https://github.com/microsoft/RulesEngine/blob/a74f73a44e38ce27c76945f15fd697c7abe5eef9/src/RulesEngine/Actions/ExpressionOutputAction.cs#L21-L22 The ruleparser is a public class and can be used to evaluate expressions

If you just want to return an object , just use outputExpression and set the object there e.g.

"OnSuccess": {
            "Name": "OutputExpression",  //Name of action you want to call
            "Context": {  //This is passed to the action as action context
               "Expression": "new (Device.Id as BodyId, Device.DateTimeUTC as EventUTCTime)"
            }
         }

abbasc52 avatar Sep 25 '22 07:09 abbasc52

@abbasc52 ,

How do I Inject the RuleExpressionParser into my custom action? while registering the custom actions in RESettings, I will not have the rule engine instance yet, Is there an example I can refer to?

I tried the second approach as I just need the object in the custom action "Expression": "new (Device.Id as BodyId, Device.DateTimeUTC as EventUTCTime)"

Unfortunately I still get it as string at the receiving end

vprabhu81 avatar Sep 26 '22 10:09 vprabhu81

@abbasc52 ,

How do I Inject the RuleExpressionParser into my custom action? while registering the custom actions in RESettings, I will not have the rule engine instance yet, Is there an example I can refer to?

I tried the second approach as I just need the object in the custom action "Expression": "new (Device.Id as BodyId, Device.DateTimeUTC as EventUTCTime)"

Unfortunately I still get it as string at the receiving end

Hi @abbasc52

I found the answer on UnitTests

Name: "OutputExpression" expression: "input1.country.ToString() + input2.totalOrders.ToString()",

"OnSuccess": {
            "Name": "OutputExpression",  
            "Context": {  //This is passed to the action as action context
               "expression": "input1.country.ToString() +  input2.totalOrders.ToString()"
            }
         }

See here

I hope this snippet can be added to the docs.

m4ss1m0g avatar Nov 29 '22 11:11 m4ss1m0g