Conditional saving on buttons

Is it OK to use this approach for conditional multiple rule input saving on button component?

a!buttonWidget(
            label: "Go Back",
            value: local!activeStep - 1,
            saveInto: {
              local!activeStep,
              if(
                local!activeStep = 1,
                a!save(
                  ri!employee,
                  null
                ),
                null
              ),
              if(
                local!activeStep = 1,
                a!save(
                  ri!address,
                  null
                ),
                null
              ),
              if(
                local!activeStep <> 1,
                a!save(
                  ri!address,
                  rule!EEDM_GetAddressDetailsById(
                    local!startAddressId
                  ).data
                ),
                null
              ),
              if(
                local!activeStep <> 1,
                a!save(
                  ri!employee.addressId,
                  local!startAddressId
                ),
                null
              ),
              if(
                local!activeStep = 2,
                a!save(
                  ri!addressUpdChoice,
                  null
                ),
                null
              )
            }

This is from milestone template which uses the same button on most steps and I need to do specific actions depending on which step I'm on.

To me, it seems fine to use IF conditions in this way and it works fine so far.

However, I haven't run into some examples of this here.

Am I using something undocumented or my "works fine" is just coincidence?

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Nope, you're following the paradigm perfectly.

    The saveInto parameter takes an array of targets or a!save() function calls.  All your if()'s do is return either an a!save() or a null.  If saveInto ignores the nulls, you can just act like your if's just return a!saves.  So your list of if()'s just becomes a list of a!save(), exactly what saveInto wants. 

    Nothing in the whole language cares how you arrive at the data as long as it's the type that it's looking for.  It just abstracts all function calls to be nothing more than whatever their output is.  You have a function whose output is an a!save(); that's good enough for saveInto().  It does not matter what it is. 

    But also, there is essentially no place in the whole language where you could not use if(), and essentially no place where you should not.  It's for everywhere, but so is almost everything else.  You could use a!forEach() to generate your list of a!save()'s there too.  I think I have before.  Or the apply() function, though that might as well be deprecated, or a helper rule, or the reduce() function, or a host of other things.  The only condition is the output of whatever it is happens to be a!save()s.

    It's no coincidence.  You have reached a higher level of understanding of how to use the expression language.  

Reply
  • +1
    Certified Lead Developer

    Nope, you're following the paradigm perfectly.

    The saveInto parameter takes an array of targets or a!save() function calls.  All your if()'s do is return either an a!save() or a null.  If saveInto ignores the nulls, you can just act like your if's just return a!saves.  So your list of if()'s just becomes a list of a!save(), exactly what saveInto wants. 

    Nothing in the whole language cares how you arrive at the data as long as it's the type that it's looking for.  It just abstracts all function calls to be nothing more than whatever their output is.  You have a function whose output is an a!save(); that's good enough for saveInto().  It does not matter what it is. 

    But also, there is essentially no place in the whole language where you could not use if(), and essentially no place where you should not.  It's for everywhere, but so is almost everything else.  You could use a!forEach() to generate your list of a!save()'s there too.  I think I have before.  Or the apply() function, though that might as well be deprecated, or a helper rule, or the reduce() function, or a host of other things.  The only condition is the output of whatever it is happens to be a!save()s.

    It's no coincidence.  You have reached a higher level of understanding of how to use the expression language.  

Children
No Data