Skip to main content
erazemk6135
March 4, 2024
Solved

Iterating over links in an array of maps doesn't work consistently

  • March 4, 2024
  • 1 reply
  • 5 views

I have an array of maps that I iterate over and generate cards with links like so:

local!selectedCard,
local!example:
    {a!map(
          icon: "first-aid",
          name: "name1",
          link: a!dynamicLink(saveInto: a!save(local!selectedCard, 1))
        ),
    a!map(
        icon: "home",
        name: "name2",
        link: a!startProcessLink(
          processModel: some process,
          processParameters: {
            /* some params */
          }
        )
      ),
      /* some more options */
      },
      {
      
      a!columnsLayout(
          columns: {
            a!columnLayout(),
            a!forEach(
              items: local!options,
              expression: a!columnLayout(
                contents: {
                  a!cardLayout(
                    contents: {
                      a!richTextDisplayField(
                        labelPosition: "COLLAPSED",
                        value: {
                          char(10),
                          char(10),
                          a!richTextIcon(
                            icon: fv!item.icon,
                            color: "SECONDARY",
                            size: "MEDIUM_PLUS"
                          ),
                          char(10),
                          char(10),
                          a!richTextItem(
                            text: fv!item.name,
                            color: "SECONDARY",
                            size: "MEDIUM",
                            style: "STRONG"
                          )
                        },
                        align: "CENTER"
                      )
                    },
                    link: fv!item.link,
                    height: "SHORT_PLUS",
                    shape: "ROUNDED"
                  )
                },
                width: "MEDIUM"
              )
            ),
            a!columnLayout()
          },
          showWhen: a!isNullOrEmpty(local!selectedCard),
          marginBelow: "STANDARD"
        )
      
      }


This doesn't work. When I click on the appropriate card, the variable local!selectedCard is still null even though I specified it should be set to 1. When I click on the process model card however that works fine. The dynamic link property of the map entry has all it's fields set to null after evaluation. Why is that so? If I use this code instead of fv!item.link for the link parameter of the card the code works:

/* card link param */
link: if(
          fv!index = 2,
          a!startProcessLink(
            processModel: some_process_model,
            processParameters: {
              /* some params */
            }
          ),
          a!dynamicLink(saveInto: a!save(local!selectedCard, fv!index))
        )

However this way it is obvious if I (or someone else) in the future add an entry to the array the index specified might be wrong and the whole thing will break.

Best answer by stefanhelzle0001

AFAIK this is one of the edge cases in SAIL. Trying to store a!save() in a local and make them evaluate as the user clicks, does not work.

But, you could work around this by storing the link target and link value separately and create the link and the a!save() inside the foreach. That's what I do in such situations.

1 reply

stefanhelzle0001
Brainy
March 4, 2024

AFAIK this is one of the edge cases in SAIL. Trying to store a!save() in a local and make them evaluate as the user clicks, does not work.

But, you could work around this by storing the link target and link value separately and create the link and the a!save() inside the foreach. That's what I do in such situations.