Skip to main content
January 13, 2023
Question

update one field of CDT array

  • January 13, 2023
  • 5 replies
  • 0 views

Hi there,

I have one CDT array

{

{a: 1,

b: "R"

},

{a: 2,

b: "E"

},

{a: 3,

b: "R"

},

}

what's the good way to update field b from "R" to "T". tried this, it does not work.

a!update(CDT.b, {1, 3}, "T")

anyone has the experience dong this?

Regards,

Lin

5 replies

davel001150
January 13, 2023

a!forEach(
    items: local!list,
    expression: if(
        fv!item.b = "R",
        update(
            data: fv!item,
            index: "b",
            value: "T"
        ),
        fv!item
    )
)

davel001150
January 13, 2023

If you need null safety, index() function on line 4

mikes0011
Brainy
January 13, 2023
If you need null safety, index() function on line 4

fun fact: as far as i can tell, "fv!item" is null-safe for dot properties much like "fv!row" is - meaning, accessing a nonexistent property simply results in a null rather than an error.

a!localVariables(
  local!asdf: {
    {
      idx: 1
    },
    {
      idx: 2
    }
  },
  
  a!forEach(
    local!asdf,
    fv!item.name
  )
)

The Expression Guru