-
Notifications
You must be signed in to change notification settings - Fork 562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom method is not being called with ExecuteActionWorkflowAsync; throwing parser error. #584
Comments
Hello @lparee, It appears that the As a result, when using To mitigate this issue temporarily, you can manually register the class as demonstrated in the example below: using RulesEngine.Models;
using System.Text.Json;
var rulesEngine = new RulesEngine.RulesEngine(new ReSettings { CustomTypes = new[] { typeof(User) } });
rulesEngine.AddWorkflow(new Workflow
{
WorkflowName = "UserNameWorkFlow",
Rules = new List<Rule>
{
new Rule
{
RuleName = "CheckFullName",
Expression = @"user.FullName() == ""Renan Pereira"""
}
}
});
var parameter = RuleParameter.Create("user", new User { FirstName = "Renan", LastName = "Pereira" });
// This works without setting the CustomTypes.
var result1 = await rulesEngine.ExecuteAllRulesAsync("UserNameWorkFlow", parameter);
Console.WriteLine(JsonSerializer.SerializeToElement(result1, new JsonSerializerOptions { WriteIndented = true }));
// This does not work without setting the CustomTypes.
var result2 = await rulesEngine.ExecuteActionWorkflowAsync("UserNameWorkFlow", "CheckFullName", new[] { parameter });
Console.WriteLine(JsonSerializer.SerializeToElement(result2, new JsonSerializerOptions { WriteIndented = true }));
Console.ReadLine();
public class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName() => $"{FirstName} {LastName}";
} This workaround involves setting |
i tested and it works fine. i wrote a demp app supporting this in my fork |
Hi Team,
I am trying to execute my workflow using ExecuteActionWorkflowAsync method of MS rule engine but here I am not being able to use custom method in an expression, it is throwing parser error while execution.
Whereas it is working fine with ExecuteAllRulesAsync method.
I need to execute my rules in a sequence within a workflow with some custom methods in execution, hence, I have to use ExecuteActionWorkflowAsync method.
Here is a sample code.
//JSON:
[
{
"WorkflowName": "MyWorkFlow",
"Rules": [
{
"RuleName": "Rule1",
"SuccessEvent": "ok",
"ErrorMessage": "Reject",
"ErrorType": "Error",
"RuleExpressionType": "LambdaExpression",
"Expression": "customMethods.doSomething()",
"Actions": {
//action
}
}
}
]
// Custom method class
public class CustomMethods
{
}
//input construction
var input1 = new RuleParameter("string1", "hello");
var cust = new RuleParameter("customMethods", customMethods);
//engine execution with action workflow
_engine.ExecuteActionWorkflowAsync("MyWorkFlow","Rule1", {input1,cust }).Result;
//throwing parsing error "doSomething" is not accessible.
//engine execution with all rules
_engine.ExecuteAllRulesAsync("MyWorkFlow",{input1,cust }).Result
//working fine.
Regards
Lokesh
The text was updated successfully, but these errors were encountered: