Skip to main content
February 9, 2024
Solved

Passing dynamical no of parameters to a rule

  • February 9, 2024
  • 7 replies
  • 0 views

Hi, I have a below rule with pre-passed 3 parameters. Now, Is there any way that I can store these parameters (para1, para2, para3) and its values (val1, val2, val3) in variables and pass them to the rule dynamically? The no of parameter will be changed as they could come from rule input or local variable.

Example: [Code] I have two variables local!para and local!val and end result is whats written in the expression is what I want. See, rule can accept 5 parameters but I have given only 2 in this case.

a!localVariables(
  local!para: {"para1", "para2"},
  local!val: {"val1", "val2"},
  rule!JS_abcRule(
    para1: "val1",
    para2: "val2"
  )
)

Best answer by mikes0011

No, that is not possible.  The best thing you can do (and honestly, I've found it to be sufficient in nearly 100% of my use cases over the past 11+ years) is to call all parameters and conditionally pass values to them.

7 replies

konduruc733182
February 9, 2024

Hello [mention:cf3dd2b16c2c40b2a395a2a168a726ea:e9ed411860ed4f2ba0265705b8793d05] 

Not sure uf i completely understand your question. But from what I understand, you want to use a set of values even if the user/process doesn’t provide values to them. 

you can have the values set in locals and use default value function.

If your question is about query filter or rule parameters you can handle it with the apply when or simple if logics.

stefanhelzle0001
February 9, 2024

Did you consider to use a list or a map?

What are you aiming for? Appian is not Java, trying add more levels of abstraction gets you quickly into unsafe waters.

mikes0011
Brainy
February 9, 2024

When you call a rule with Keyword Syntax (like you've done in your example), all parameters are optional as long as you've set up the rule to handle nulls.  From the calling rule or interface, you can invoke any subset (between 1 and all) of the parameters (it can't be zero unless the rule has none), and each one you utilize can conditionally be passed a value or not, depending on the logic you prefer.

There's not really any additional way to "dynamically pass parameters", if i'm even reading your question right, because in any one invocation of the rule, any parameters you pass in must be hardcoded into the rule call (but this is where you can fall back on conditionally passing in a value for individual items if you wish).

February 9, 2024

Yeah, I want to pass parameters like below in the rule thats not hardcoded and it should give what I written in expression original question. I guess its not possible.

a!localVariables(
  local!para: {"para1", "para2"},
  local!val: {"val1", "val2"},
  rule!JS_abcRule(
    local!para[1]: local!val[1],
    local!para[2]: local!val[2]
  )
)

mikes0011
mikes0011Answer
Brainy
February 9, 2024

No, that is not possible.  The best thing you can do (and honestly, I've found it to be sufficient in nearly 100% of my use cases over the past 11+ years) is to call all parameters and conditionally pass values to them.