Skip to main content
vengh
August 26, 2021
Question

Record Search Box in GridField - Searching Names (First and Last)

  • August 26, 2021
  • 7 replies
  • 1 view

As far as I know, the record search box on a record-backed gridField will do a search on the raw data of all of the columns in the grid. For example, searching for "username1" will return any rows that contain "username1" in any of the columns' raw data, regardless of how the data is formatted. If the column data was formatted to show First Name or Last Name, a search for "username1" would still return the row; however a search for the First Name value or Last Name value would not return any results, as this is a formatted value and not the raw value.

I have a requirement for the search box to enable searching on first name and last name values, not only username. Are there any elegant solutions to enable this?

The only ideas I have are not very elegant:

  1. create a daily username sync process so the database has the user's first and last names, then update the view / cdt to include these values.
  2. convert the record to an expression backed record and construct the datasubset with the first name and last name values

7 replies

danny.verb
August 26, 2021

Using custom fields on a record type you can create separate fields for first name and last name. This removes the need to update a view or CDT.

vengh
venghAuthor
August 26, 2021

This does not solve this issue. This issue is that the Appian record search does not return matches on formatted values (i.e. values generated by passing the data into an expression). In your proposed solution, the username value will be formatted to first and last name display values, using the user() function. The native search only searches on the raw data, in this case, the username. So even though the column displays "Wen" for first name, the data that backs that column is a username "whuynh", so searching "Wen" won't return this row. A search for "whuynh" will return the row. Does that make sense?

danny.verb
August 26, 2021

Starting in Appian 21.2 we have custom fields on record types which are different than fields you format on the grid.

https://docs.appian.com/suite/help/21.2/custom-record-fields.html

When referencing these fields, the search bar will pick up these fields

August 26, 2021

You could make your own custom search box bound to a local variable, and then filter the grid based on that variable, like so:

{
  a!localVariables(
    local!search:"",
  a!boxLayout(
    label:"users",
    contents:{
      a!textField(
        label: "",
        labelPosition: "ABOVE",
        placeholder: "Search Users",
        value: local!search,
        saveInto: local!search,
        refreshAfter: "UNFOCUS",
        validations: {}
      ),
  a!gridField(
    label: "Read-only Grid",
    labelPosition: "COLLAPSED",
    data: a!recordData(
      recordType: 'recordType!{SYSTEM_RECORD_TYPE_USER}User',
      filters: a!queryLogicalExpression(
        operator: "OR",
        filters: {
          a!queryFilter(
            field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{username}username',
            operator: "includes",
            value: local!search
          ),
          a!queryFilter(
            field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{firstName}firstName',
            operator: "includes",
            value: local!search
          ),
          a!queryFilter(
            field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{lastName}lastName',
            operator: "includes",
            value: local!search
          ),
          a!queryFilter(
            field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{email}email',
            operator: "includes",
            value: local!search
          )
        },
        ignoreFiltersWithEmptyValues: true
      )
    ),
    columns: {
      a!gridColumn(
        label: "user",
        sortField: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{username}username',
        value: fv!row['recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{username}username']
      ),
      a!gridColumn(
        label: "email",
        sortField: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{email}email',
        value: fv!row['recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{email}email'],
        align: "START"
      )
    },
    validations: {},
    showSearchBox: false,
    showRefreshButton: false
)
    }))}

vengh
venghAuthor
August 26, 2021

Thanks for the suggestion. This looks like a reasonable solution. We want to use the native search, so Danny's solution would fit more nicely.