Help

Auto link certain records based on an input

850 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Liz_Zimmerman1
4 - Data Explorer
4 - Data Explorer

I’m working on a new personnel base and I’m having trouble wrapping my head around how to execute a link I’d like to see. Here’s the scenario:

I have 1 table of Staff. They are numbered based on the order I would like to hire them to work an event. So, if I need 5 people at an event, the staff numbered 1, 2, 3, 4, and 5 will be called in for the event. If I only need 2 people for the next event, it will still be staff #1 and 2.

I have another table of Events. Here I put in the number of staff I need, and I would really like to build a way for it to auto pull and link the appropriate staff members.

Any ideas?!

1 Reply 1

This would need an Automation that includes a script. You should try something like the following:

Automation Steps

  1. Type: Run a script
    Input Variables:
    • key: count, value: the trigger record's {Necessary Staff Count} field

Script:

let {count} = input.config()
let table = base.getTable("Staff")
let query = await table.selectRecordsAsync({
    sorts: [
       {field: "Staffing Priority"},
    ]
})
let records = query.records.filter(record => Number(record.getCellValue("Staffing Priority")) <= count)

let recordIDs = records.length > 0 ? records.map(record => record.id) : []

output.set(recordIDs , recordIDs)
  1. Type: Update record
    Table: Events
    Record ID: record ID from trigger
    Fields:
    • {Staff} = output from the Run script action