Can we save the rules or values in with()?

a

  Discussion posts and replies are publicly visible

  • Hi

    Yes, we can create a rule which is wrapped in with(). Basically this type of rule is used when input variable is changing repetitively. Similarly we can change/update the local variable value which created within with() function but through the a!save().

    For more info please visit the following URL:

    docs.appian.com/.../fnc_evaluation_with.html


    Thanks
    Aditya
  • Yes, you can save values in with(). It really depends on your use case. If your data requires that it updates everytime the variables changed you will need to use with(), Otherwise, use load() if you expect the values to load only one time.
  • 0
    Certified Lead Developer

    Hi tirumalar0001 Adding few points to the above comments.

    Yes it's true that you can refresh a variable(defined inside load, as a rule input or a node input) by the use of with() on each user interaction/evaluation (in fact the same can be achieved by using load as well) but you cannot use a!save() / saveInto referencing to a local variable which is defined inside with() as this will break your interface saying:

    Interface Definition: Expression evaluation error: An error occurred while executing a save: Expression evaluation error: The save target is a with() variable. The save target must be a load() variable, process variable, or node input (or a rule input passed one of those three). with() variables are reinitialized with each evaluation and therefore cannot be used as save targets.

    You can re-evaluate / update / insert / delete the value of a rule input / local variable defined under load() but you cannot do the same when a variable is defined inside with() as they are tend to re-initialized upon each user interaction/evaluation as shown in below code snippet:

    /* Here saveInto will cause to break your Interface because the variable is defined within with() and being used at saveInto */
    with(
      local!firstName_txt,
      a!formLayout(
        label: "With Component Demo",
        contents: {
          a!textField(
            label: "First Name",
            required: true(),
            value: local!firstName_txt,
            saveInto: local!firstName_txt /*This will cause this issue */
          )
        },
        buttons: {
          a!buttonLayout(
            primaryButtons: {
              a!buttonWidgetSubmit(
                label: "SUBMIT",
                style: "PRIMARY"
              )
            }
          )
        }
      )
    )

    Hope this will help you.

  • 0
    Certified Lead Developer

    If I understand the real meaning of the question, the answer is NOPE.

    You can CREATE variables in a with().
    You can INVOKE variables in a with().
    with() REEVALUATES variables.
    You can use with() variables wherever you want, except SAVE INTO or a!save().

    When you attempt to SAVE a variable or value to a with() local variable, you then reevaluate the entire form including the definition of the with variable. The with() then gets overwritten with the value determined by its specification, and the value you SAVED is lost.

    You can only use local variables configured in a load() as part of a saveInto: or a!save(). When those get SAVED into, they aren't immediately reevaluated and replaced, so the value you SAVED is maintained.

    If by SAVE you mean saveInto: or the a!save() function, no, you can't SAVE values in with().