Hello All, How can we use like java reflexion in SAIL to can call dyn

Hello All,

How can we use like java reflexion in SAIL to can call dynamically a rule expression or function from a rule expression?
For example something like that: invoke("rule!name",{param1;param2})
If it´s not ootb is there any plugin to do that?

thank you in advance for you answer,
Best regards.
Alex

OriginalPostID-183169

OriginalPostID-183169

  Discussion posts and replies are publicly visible

  • Hi Alex, SAIL does support passing functions(or rules) to other rules or functions. You can create a rule with "AnyType" as a parameter. Then you can pass the ruleName while calling that rule. For more details got through this link:forum.appian.com/.../Expressions.html
  • An example: Create a rule named TEST_DYNAMICALLY_CALL_RULE with input params 'ruleOrFunref'(Any Type) and ''params (Number - array)'. Define the rule as: ri!ruleOrFunRef(ri!params). Now you can call this rule from another rule and pass the function or ruleName. For eg: you can call it like this:
    rule!TEST_DYNAMICALLY_CALL_RULE(
    fn!sum,
    {1,2,3}
    ).

    So, here we are passing a rule reference to another rule with the parameters required. This paradigm is quite common in Functional Programming languages(en.wikipedia.org/.../Functional_programming) where a function takes other functions as arguments or returns a function (languages like LISP, JavaScript, Haskell, Clojure etc. support this.) I hope this is exactly what you wanted to know about.
  • Thank you Chetany but I know this "part of solution". I mean part because your solution is dynamic but is not a total reflexion approach. You are not passing the function name but the pointer on this function.
    Your solution will be reflexion programming if you will call the function sum like this: rule!TEST_DYNAMICALLY_CALL_RULE(
    "fn!sum",
    {1,2,3}
    )
    To be sure that is dynamic : when you click on precedent from the rule that call TEST_DYNAMICALLY_CALL_RULE the function or rule passed in parameter has to be ignored.
    So do you know how I can do it?
  • Hi Alex, I now understand what you meant. You want to pass the function name rather than a reference to the function. As far as I know, there is no OOTB solution for this. But, it can be done via creating custom Appian plugin code. In your Java method you need to take the rule or function name as input and then get the actual function or rule name. There are APIs for getting a rule or constant by name. Refer ContentService class in Appian's Java API. There are some methods which can return you the rule or function by name. Once you get that function or rule, you can then pass the parameters to it and evaluate it in Java code and return the result.
  • If I understand the context correctly, as per my knowledge we can invoke a rule or function by just passing its reference to other rule via it's rule inputs. And 'APN_uiGridTextColumnAuto', one of the Appian common objects is a classic example for this which has been shown in the attached picture. In this rule, the rule input 'formatter', which is of 'Any Type' data type, has the capability to accept a rule or function by reference. Example: rule!APN_uiGridTextColumnAuto(formatter:fn!tostring) or rule!APN_uiGridTextColumnAuto(formatter:rule!myRuleName)

    Feel free to correct me if I am wrong, as I have been thinking that that the possibility of invoking any rule dynamically(as described in the above examples) can't be denied.

  • @sikhivahans, the OP knows about passing rule references to other rules/functions as inputs. He wants to know if rather than passing a reference to a rule or function, can we just pass the name of that function or rule and execute it.