Skip to main content
prashants1485
March 30, 2023
Solved

Index Function

  • March 30, 2023
  • 3 replies
  • 0 views

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

Best answer by stefanhelzle0001

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
March 30, 2023

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
March 30, 2023

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

March 30, 2023
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.