-
Notifications
You must be signed in to change notification settings - Fork 604
Actions
Abbas Cyclewala edited this page Oct 4, 2020
·
6 revisions
As a part of v3, Actions have been introduced to allow custom code execution on rule result. This can be achieved by calling ExecuteActionWorkflowAsync instead of ExecuteRule method of RulesEngine
| ExecuteRule | ExecuteActionWorkflowAsync |
|---|---|
| Takes workflowName as input and executes all rules under it | Takes workflowName and ruleName as an input and executes only that rule and any corresponding action associated with it |
| Does not run actions even if specified in the Rules object | Runs the actions specified in the Rules object |
| Useful when looking for only true or false as result | Useful for returning complex results or performing some operation on rule success or failure |
| Returns List of RuleResultTree for all the rules | Returns output of action, List of RuleResultTree of all the rules executed |
RulesEngine provides two actions inbuilt which cover major scenarios related to rule execution
This action evaluates an expression based on the RuleParameters and returns its value as Output
Define OnSuccess or OnFailure Action for your Rule:
Call ExecuteActionWorkflowAsync with the workflowName, ruleName and ruleParameters
var result = await rulesEngine.ExecuteActionWorkflowAsync("inputWorkflow","GiveDiscount10Percent",ruleParameters);
Console.WriteLine(result.Output); //result.Output contains the evaluated value of the action
{ "WorkflowName": "inputWorkflow", "Rules": [ { "RuleName": "GiveDiscount10Percent", "SuccessEvent": "10", "ErrorMessage": "One or more adjust rules failed.", "ErrorType": "Error", "RuleExpressionType": "LambdaExpression", "Expression": "input1.couy == \"india\" AND input1.loyalityFactor <= 2 AND input1.totalPurchasesToDate >= 5000 AND input2.totalOrders > 2 AND input2.noOfVisitsPerMonth > 2", "Actions": { "OnSuccess": { "Name": "OutputExpression", //Name of action you want to call "Context": { //This is passed to the action as action context "Expression": "input1.TotalBilled * 0.9" } } } } ] }