Passing Expressions as Expression Parameters

Certified Lead Developer

Are there any plans to allow for the passing expressions as expression parameters? I think this would be an incredibly useful feature to add to the expression language.

  Discussion posts and replies are publicly visible

  • You can pass expressions as rule inputs to other expressions. Are you asking for something different from this?
  • 0
    Certified Lead Developer
    in reply to Colton Beck

    It could be the same thing. Can you provide me with the link to where this is described? Otherwise, if you can demonstrate the syntax that should suffice. Thanks!

  • You can take a look at the general expression documentation here.

    You can play around with this in the expression editor. For example, you can create a rule called rule!getDateByDateTime which takes in a datetime parameter. Instead of directly passing a datetime, you can pass another rule like rule!getDatetimeByDateAndTime, which will take date and time parameters.

     

    You can put these together like this: rule!getDateByDateTime(rule!getDatetimeByDateAndTime(ri!date, ri!time))

     

    Let me know if you have any other questions.

  • +1
    Certified Lead Developer
    in reply to Colton Beck

    Thank you. Yes, I am familiar with what you describe above. I am however referring to the passing of an expression rule as an argument ( rule input ) to another expression rule; not passing the result of an expression rule to another expression rule.

    I have experimented and I believe I have answered my own question. Here is an explanation if you're interested. It relates to the scenario of another thread we have been discussing ( https://community.appian.com/discussions/f/general/11194/accessing-cdt-field-properties ). So, I have a reusable interface expression that accepts AnyType of rule input where the inputs can be different CDTs. These CDTs do however have common field names, i.e. name, description. I want to pass a CDT specific validation ( expression rule ) as a rule into the interface expression that checks if the value entered for the name field already exists in the database, i.e. through the use of a!queryEntity. This would of course be different for each CDT. So, for example, I would have two expression rules named isCustomerNameUnique(name) and isProductNameUnique(name). Each of them would check if the name is unique and then return either null if it unique or a validation message indicating the the name is not unique, i.e. "The customer name already exists." or "The product name already exists.". The interface expression would then accept a rule input of AnyType called validation as well as a rule input of AnyType called entity. I could then invoke that expression when I need to validate user input. For example:

    a!textField(
      label: "Name",
      value: ri!entity.name,
      saveInto: ri!entity.name,
      validations: ri!validation(ri!entity.name)
    )

    Works! Thanks for getting me to think through this carefully! The answer came to me when I explored the concepts detailed here : https://docs.appian.com/suite/help/17.3/Expressions.html#passing-functions-rules-and-data-types-as-arguments

    What do you think?

  • You can pass expression rule references via Any Type parameters. For instance, in the below example, we control the transformation function that is used to change a local variable when a button is clicked. When the first button is pressed, the value will have the logarithm with base 5 taken. When the first button is pressed, the value with be taken to the 5th power. This works with any expression rule in addition to functions.

    Make a button widget rule called myButtonWidget with inputs ri!value and ri!transformFunction with the following code:

    a!buttonWidget(

     label: "Transform Value",

     saveInto: a!save(ri!value, ri!transformRule(ri!value))

    )

    Then, in an interface, call this rule twice with different transformation functions:

    load(

      local!value: 10,

    a!buttonLayout(

     primaryButtons: {

       rule!myButtonWidget(local!value, log(_, 5)),

       rule!myButtonWidget(local!value, power(_, 5))

    }

    )

    )

  • Ah, it looks like you figured it out on your own!
  • 0
    Certified Lead Developer
    in reply to gianninol
    Yes! Thank you for your efforts! Much appreciated! I think this is really a great feature...