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

    This looks correct, though I think there's a chance you might have issues unless you replace "null" with an empty set {} for the non a!save portion of the if statement.  "saveInto" requires a list of saves, and items in the list that return an empty set are safely ignored, but items in the list that return "null" will show up as an entry in the list, which Appian may or may not handle properly right now.

Reply
  • +1
    Certified Lead Developer

    This looks correct, though I think there's a chance you might have issues unless you replace "null" with an empty set {} for the non a!save portion of the if statement.  "saveInto" requires a list of saves, and items in the list that return an empty set are safely ignored, but items in the list that return "null" will show up as an entry in the list, which Appian may or may not handle properly right now.

Children