Help

Re: Filter records by values in linked cell fields for Select Component

442 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Justin_Yorick
4 - Data Explorer
4 - Data Explorer

My application has several Select components which the user can use to enter information. The first two fields have only a small number of options. The third field has over 70 options and can be tedious to use.

I want to use the values selected in the first two Select components to filter the available options presented to the user in the third Select.

The options in the third select are pulled from records in the base. These records have linked fields. Some of these linked field values are options chosen in the previous Select components.

So, lets say I want to filter returned records from a table where values in a linked field (s) match either the record ID of string value in said linked field.

2 Replies 2
const thirdSelectFieldsOptions = records
.filter(record => record.getCellValue(linkRecordFieldId).map(val => val.id).join("") === secondSelectFieldValue)
.map(record => {value: record.id, label: record.name})

^ something like that.

Thanks @Kamille_Parks . When I attempt to call records.filter I get the following error :

maintenanceProcedureNameRecords.filter is not a function

I tried writing maintenanceProcedureNameRecords as an array, and got a little bit further. SO i have something like this.

function ProcedureSelect ({systemId},maintenanceProcedureNameRecords,setProcedureId,procedureId){
  const newbase=useBase()
  let tableMaintenanceTasks=newbase.getTableByNameIfExists('Maintenance Tasks')
  if(!systemId){
    return null
  }else{
  const linkRecordFieldId=tableMaintenanceTasks.getFieldByNameIfExists('Top Level System');
  const filteredProcedureOptions = [maintenanceProcedureNameRecords].filter(record => (record.getCellValue(linkRecordFieldId).map(val => val.id).join("") === systemId.value)).map(record => ({value: record.id, label: record.name}))


return (
  <Select
  onChange={setProcedureId}
  options={filteredProcedureOptions}
  value={procedureId}
  />
)

Executing this gets me the following error:

TypeError: record.getCellValue is not a function

It seems like there has to be something simple/fundamental that I am missing here.