Skip to main content
April 6, 2023
Question

How can I convert expression?

  • April 6, 2023
  • 5 replies
  • 1 view

data: local!noteData,
      columns: {
        a!forEach(
          items: local!fields,
          expression: a!gridColumn(
            label: fv!item,
            value: index(fv!row, fv!item, "")
          )
        )
      },

How do I convert the above code, this part:

expression: a!gridColumn(
label: fv!item,
value: index(fv!row, fv!item, "")
)


To something like:

a!gridColumn(
label: "Note",
value: index(fv!row, "Note", "")
),

a!gridColumn(
label: "Name",
value: index(fv!row, Name, "")
)

Where both Note and Name are keys in a dictionary.

Thanks

5 replies

peter.lewis
Employee
April 6, 2023

You probably want to use the a!keys() function. Here's an example:

a!localVariables(
  local!data: {
    a!map(note: "Sample Note", name: "Sample Name"),
    a!map(note: "Sample Note 2", name: "Sample Name 2"),
  },
  a!gridField(
    data: local!data,
    columns: a!forEach(
      items: a!keys(index(local!data, 1, {})),
      expression: a!gridColumn(
        label: fv!item,
        value: index(fv!row, fv!item, "")
      )
    )
  )
)

petel0001Author
April 6, 2023

However, by using the Keys function I get all of the keys, which I do not want.
Using your example I've added a description key, I do not want that key to be displayed.
In the local!data I also have the primary key value for the record, not too useful fore the end user either.

a!localVariables(
  local!data: {
    a!map(note: "Sample Note", name: "Sample Name", description: "i am a description"),
    a!map(note: "Sample Note 2", name: "Sample Name 2", description: ""),
  },
  a!gridField(
    data: local!data,
    columns: a!forEach(
      items: a!keys(index(local!data, 1, {})),
      expression: a!gridColumn(
        label: fv!item,
        value: index(fv!row, fv!item, "")
      )
    )
  )
)

peter.lewis
Employee
April 6, 2023

That's fair, but if you're explicitly choosing certain fields, I think it's easier to just define them yourself. Instead of using a!keys, just put a list with the fields you plan to display.

April 6, 2023

a!localVariables(
  /* Example */
  local!data: {
    a!map(Note: "Note1", Name: "Name1", Field: 123),
    a!map(Note: "Note2", Name: "Name2", Field: 123)
  },
  local!fields: { "Note", "Name" }, /* Fields required */
  a!gridField(
    data: local!data,
    columns: a!forEach(
      items: local!fields,
      expression: a!gridColumn(
        label: fv!item,
        value: index(fv!row, fv!item, "")
      )
    )
  )
)

Please, test it and let me know if this solve your problem.