Skip to main content
April 11, 2025
Solved

Map Type won't support append method

  • April 11, 2025
  • 5 replies
  • 0 views

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

Best answer by zakarym8213

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

5 replies

stefanhelzle0001
April 11, 2025

The value you want to append something to, needs to be of a list type.

April 11, 2025

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

April 11, 2025

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()?

stefanhelzle0001
April 11, 2025

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)))
)