Skip to main content
prashants1485
New Participant
Mar 30, 2023 6:52 PM UTC
Solved

Index Function

Hi Experts,

How to use Index Function to extract  whole row data from a list of records based on one record field value?

We want to extract one row data from local! data where one fieldname : id has a value: 100051

stefanhelzle0001
Brainy
Mar 30, 2023 7:00 PM UTC

To get a single item you can just use the displayvalue function.

a!localVariables(
  local!data: {
    a!map(id: 7, name: "Max"),
    a!map(id: 42, name: "Otto"),
    a!map(id: 100, name: "Joe"),
  },
  displayvalue(
    42,
    local!data.id,
    local!data,
    null
  )
)

3 replies

stefanhelzle0001
Brainy
Mar 30, 2023 7:00 PM UTC

To get a single item you can just use the displayvalue function.

a!localVariables(
  local!data: {
    a!map(id: 7, name: "Max"),
    a!map(id: 42, name: "Otto"),
    a!map(id: 100, name: "Joe"),
  },
  displayvalue(
    42,
    local!data.id,
    local!data,
    null
  )
)

davel001150
Inspiring
Mar 30, 2023 7:18 PM UTC

Good to know.  I always used index( array of CDT, wherecontains( ID I want to find, arrayofCDT . idField))

sanchitg0002
Inspiring
Mar 30, 2023 8:04 PM UTC
To get a single item

This is the issue with displayvalue that it only searches for the first occurrence of the given value in the list and returns corresponding replacement value, dk when they will enhance it to return multiple values.

That's why we always use a generic rule to perform such operation.

 

index(
    local!data,
    wherecontains(42, local!data.id),
    null
  )

Although in this case it will work nevertheless, assuming that the searched value is always unique here.