Map Type won't support append method

append(ri!selectedCards, save!value)

This code above is getting the following error:

Interface Definition: Expression evaluation error [evaluation ID = 788c2:8d9d9] : An error occurred while executing a save: Expression evaluation error at function 'append' [line 99]: Insert is not supported for Map types

 

- ri!selectedCards' type is Map Type like local!options

- fv!item comes from a loop through local!options:

  local!options: {
    a!map(
      id: 1,
      icon: "home",
      name: "House",
      desc: "A single family home, townhouse, or duplex"
    ),
    a!map(
      id: 2,
      icon: "building",
      name: "Condo",
      desc: "A multi-family building in which you own a unit"
    ),
    a!map(
      id: 3,
      icon: "coins",
      name: "Coin",
      desc: "A coin icon to appear"
    )
  },

- save!value is the same as fv!item

link: a!dynamicLink(
  value: fv!item,
  saveInto: a!save(
    ri!selectedCards,
    if(
      ri!allowMultiple,
      if(
        contains(
          tointeger(ri!selectedCards.id),
          tointeger(save!value.id)
        ),
        difference(
          ri!selectedCards,
          { save!value }
        ),
        
        append(ri!selectedCards, save!value)
        
      ),
      save!value
    )
  )
),

How could I deal with this error on a scenario I want to allow multiple selections if I cannot append? The fun part is that the difference method is working with no problems at all

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Senior Developer

    You should be able to use the update() to handle this.  Replace your append() with update() like below...

    a!update(
      data: local!options,
      index: length(local!options)+1,
      value: save!value
    )

    This update assumes that save!value is a map like the other values in your local!options

  • Thanks, I was able to do that through your example

    reject(
      fn!isnull,
      a!update(
        data: ri!selectedCards,
        index: length(local!options) + 1,
        value: save!value
      )
    )

    Although, something that bothers me a little is that I am getting the following after some selecting and deselecting:

    {
      a!map(),
      a!map(
        id: 3,
        icon: "coins",
        name: "Coin",
        desc: "A coin icon to appear"
      ),
      a!map(
        id: 2,
        icon: "building",
        name: "Condo",
        desc: "A multi-family building in which you own a unit"
      ),
      a!map(
        id: 1,
        icon: "home",
        name: "House",
        desc: "A single family home, townhouse, or duplex"
      )
    }

    How can I could I somehow "reject" the empty a!map()?

Reply
  • Thanks, I was able to do that through your example

    reject(
      fn!isnull,
      a!update(
        data: ri!selectedCards,
        index: length(local!options) + 1,
        value: save!value
      )
    )

    Although, something that bothers me a little is that I am getting the following after some selecting and deselecting:

    {
      a!map(),
      a!map(
        id: 3,
        icon: "coins",
        name: "Coin",
        desc: "A coin icon to appear"
      ),
      a!map(
        id: 2,
        icon: "building",
        name: "Condo",
        desc: "A multi-family building in which you own a unit"
      ),
      a!map(
        id: 1,
        icon: "home",
        name: "House",
        desc: "A single family home, townhouse, or duplex"
      )
    }

    How can I could I somehow "reject" the empty a!map()?

Children
  • +1
    Certified Lead Developer
    in reply to Silas. B. Ferreira

    a!localVariables(
      local!list: {
        a!map(),
        a!map(
          id: 3,
          icon: "coins",
          name: "Coin",
          desc: "A coin icon to appear"
        ),
        a!map(
          id: 2,
          icon: "building",
          name: "Condo",
          desc: "A multi-family building in which you own a unit"
        ),
        a!map(
          id: 1,
          icon: "home",
          name: "House",
          desc: "A single family home, townhouse, or duplex"
        )
      },
      remove(local!list, where(local!list.id = null(type!Integer)))
    )

  • Thanks. That was exactly what I needed. There goes my complete answer:

    link: a!dynamicLink(
      value: fv!item,
      saveInto: a!save(
        ri!selectedCards,
        if(
          ri!allowMultiple,
          if(
            and(a!isNotNullOrEmpty(save!value.id),
            a!isNotNullOrEmpty(ri!selectedCards),
            contains(
              tointeger(ri!selectedCards.id),
              tointeger(save!value.id)
            )),
            difference(
              ri!selectedCards,
              { save!value }
            ),
            
            a!localVariables(
              local!list: reject(
                fn!isnull,
                a!update(
                  data: ri!selectedCards,
                  index: length(local!options) + 1,
                  value: save!value
                )
              ),
              remove(
                local!list,
                where(local!list.id = null(type!Integer))
              )
            )
            
          ),
          save!value
        )
      )
    ),

    It's working as expected now.

    Thank you both