0

Can anyone Please guide me how can I create an aggregator like SUM(), AVG() in Codeeffects RuleEditor. And these should be passed with set of integer values from the rule editor.

Like if there is an attribute like score which is of int type.........

Rule will be like:

If score equal to Zero then set score to SUM(10,20,30,40)

After this is should get this score as 100

Willeke
  • 14,578
  • 4
  • 19
  • 47
Akhil
  • 31
  • 6

1 Answers1

1

Define a list of integers in your source class:

public List<int> Integers {get;set;}

Define two action methods as well:

public void Sum ( List<int> list )
{
    return list.Sum( );
}
public void Add ( int i )
{
    this.Integers.Add( i );
}
public int Modulus (int operandOne, int operandTwo)
{
    return operandOne % operandTwo;
}

Now give your class as the source to the rule editor and create your rule:

If Modulus( Score, 2 ) is equal to 3
    then
        Add(10) and Add(20) and Add(30) and Add(40) and
        set Score to Sum ( Integers )
Alex
  • 566
  • 1
  • 6
  • 14
  • Thanks for the quick answer but I want to give like: SUM(1,2,3,4,5) This number of the integers that are going to be passed to the SUM from the front end are UnKnown In prior. – Akhil Jul 15 '20 at 12:05
  • I edited my answer. Please consider checking your question as answered – Alex Jul 16 '20 at 00:46
  • Ok, So we can not send the values with out declaring some method to pass them. – Akhil Jul 16 '20 at 05:23
  • I have another request.... Can we add Modulo Operator while using calculations. Because I did not see modulo operator in the drop down when writing calculations. – Akhil Jul 16 '20 at 05:25
  • 1
    You can pass int values into an action method if the number of params is predefined. For example, the method public void Sum ( int one, int two, int three, int four ) { ... } would work just fine as a rule action, but this would be a very primitive and limiting solution of your case; the example in my answer is much more flexible. – Alex Jul 16 '20 at 18:33
  • You can extend any functionality of the editor by using in-rule methods. I added the Modulus method to my example and edited the rule in order to show its use. – Alex Jul 16 '20 at 18:39
  • Can't we simply use modulo whide doing calculations like: if score is equal to 0 then set score to 12%5 – Akhil Jul 17 '20 at 07:06
  • No, a default modulus operator is not supported. – Alex Jul 17 '20 at 16:48
  • Please consider marking this one as answered. Thanks. – Alex Jul 18 '20 at 14:42