How to define a local variable to be a list?

I defined local!valuelist from a!localVariables, however, it is not a list so i can't saveinto form such as local!valuelist.username,local!valuelist.password, how can i transfer the format of this local value?

  Discussion posts and replies are publicly visible

  • I'm not entirely sure what you're trying to do but see this code for a local variable that is a list. If this doesn't help then you'll need to give more specific information.

    Note that I've used two different ways of referencing where I want things saved. They function exactly the same.

    1. Quoted square brackets indexing (eg. local!valueList[fv!index]["username"])
    2. Dot notation (eg. local!valueList[fv!index].password)

    a!localVariables(
      local!valueList,
      {
        a!forEach(
          items: local!valueList,
          expression: a!sideBySideLayout(
            items: {
              a!sideBySideItem(
                item: a!textField(
                  label: concat(
                    "Username ",
                    fv!index
                  ),
                  labelPosition: "ADJACENT",
                  value: index(
                    fv!item,
                    "username",
                    {}
                  ),
                  saveInto: local!valueList[fv!index]["username"]
                )
              ),
              a!sideBySideItem(
                item: a!textField(
                  label: concat(
                    "Password ",
                    fv!index
                  ),
                  labelPosition: "ADJACENT",
                  value: index(
                    fv!item,
                    "password",
                    {}
                  ),
                  saveInto: local!valueList[fv!index].password
                )
              ),
              a!sideBySideItem(
                item: a!richTextDisplayField(
                  label: concat(
                    "Delete row ",
                    fv!index
                  ),
                  labelPosition: "COLLAPSED",
                  value: a!richTextIcon(
                    icon: "times",
                    color: "NEGATIVE",
                    link: a!dynamicLink(
                      value: remove(
                        local!valueList,
                        fv!index
                      ),
                      saveInto: local!valueList
                    )
                  )
                )
              )
            }
          )
        ),
        a!richTextDisplayField(
          label: "Add new entry to list",
          labelPosition: "COLLAPSED",
          value: {
            a!richTextIcon(
              icon: "plus-circle",
              link: a!dynamicLink(
                value: {
                  username: loggedInUser(),
                  password: "password123"
                }
              )
            ),
            a!richTextItem(
              text: "  Add new item to list",
              link: a!dynamicLink(
                value: append(
                  local!valueList,
                  {
                    username: loggedInUser(),
                    password: "password123"
                  }
                ),
                saveInto: local!valueList
              )
            )
          }
        )
      }
    )

    You could also explore the a!map() function rather than creating a dictionary such as what I did in the "+ Add new item to list" saves (starting at lines 68 and 79)

  • In addition, all you need to do to define your local variable as a list is utilize {} in it's definition.  Here's an example of saving into index 2 of an empty local!valuelist variable:

    a!localVariables(
      local!valuelist: {},
      {
        a!richTextDisplayField(
          label: "List:",
          value: a!forEach(
            items: local!valuelist,
            expression: {
              a!richTextItem(
                text: concat("Item ",fv!index,": ",fv!item)
              ),
              char(13)
            }
          )
        ),
        a!buttonArrayLayout(
          align: "START",
          buttons: {
            a!buttonWidget(
              label: "Save",
              value: "B",
              saveInto: a!save(local!valuelist[2],{username: save!value})
            )
          }
        )
      }
    )

  • 0
    Certified Lead Developer

    Key thing to understand is that you cannot "define" a local variable at all.  I've done tests, and I can confirm that a local variable takes on the type of whatever you save to it.

    So the answer is to save an array to the local variable when you create it.  It can be an empty array.  That's  {}.