How do I determine if a column name exists in an array or datasubset?

How do I determine if a column name exists in an array or datasubset?

Say for example, the below expression when executed returns that datasubset has two fields /columns names - firstName and secondName. I want to find out if any string "xyz" is present as a field or column in a datasubset /array.

todatasubset({
type!Column(field: "username", alias: "un", visible: true),
type!Column(field: "firstName", alias: "first", visible: false),
type!Column(field: "lastName", alias: "last", visible: true)
},
a!pagingInfo(startIndex: 1, batchSize: 2, sort:{field: "alias", ascending: true})
)
.data

when executed returns the below result

[field=firstName, alias=first, visible=false], [field=lastName, alias=last, visible=true]

OriginalPostID-152071

OriginalPostID-152071

  Discussion posts and replies are publicly visible

Parents
  • I think you might want to know how to check if a datasubset contains a column to show on the screen. Since you set batch size is 2, so only 2 columns will be shown. If so, you can do it in the following way.
    = load(
    local!datasubset: todatasubset(
    {
    type!Column(
    field: "username",
    alias: "un",
    visible: true
    ),
    type!Column(
    field: "firstName",
    alias: "first",
    visible: false
    ),
    type!Column(
    field: "lastName",
    alias: "last",
    visible: true
    )
    },
    a!pagingInfo(
    startIndex: 1,
    batchSize: 2,
    sort: {
    field: "alias",
    ascending: true
    }
    )
    ).data,
    local!displayColumns: local!datasubset,
    {
    a!textField(
    label: "Test column exists or not",
    value: if(
    fn!contains(
    local!displayColumns.field,
    "username"
    ),
    "The column exists",
    "The column is missing"
    ),
    readOnly: true
    ),
    a!textField(
    label: "all columns",
    value: local!datasubset.field,
    readOnly: true
    )
    }
    )
Reply
  • I think you might want to know how to check if a datasubset contains a column to show on the screen. Since you set batch size is 2, so only 2 columns will be shown. If so, you can do it in the following way.
    = load(
    local!datasubset: todatasubset(
    {
    type!Column(
    field: "username",
    alias: "un",
    visible: true
    ),
    type!Column(
    field: "firstName",
    alias: "first",
    visible: false
    ),
    type!Column(
    field: "lastName",
    alias: "last",
    visible: true
    )
    },
    a!pagingInfo(
    startIndex: 1,
    batchSize: 2,
    sort: {
    field: "alias",
    ascending: true
    }
    )
    ).data,
    local!displayColumns: local!datasubset,
    {
    a!textField(
    label: "Test column exists or not",
    value: if(
    fn!contains(
    local!displayColumns.field,
    "username"
    ),
    "The column exists",
    "The column is missing"
    ),
    readOnly: true
    ),
    a!textField(
    label: "all columns",
    value: local!datasubset.field,
    readOnly: true
    )
    }
    )
Children
No Data