Help

Re: Job Queue Number

754 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Cheyne_Toomey
4 - Data Explorer
4 - Data Explorer

Hi there, I am wondering if it is possible to assign records a queue number? I have created a view that would be great if all records in this view are numbered >1 and all other records 0 or something similar.

This is so customers can log in and see their order is number xxx in the queue.

Thanks!

3 Replies 3

It’s not possible to directly check a record’s view assignment. However, you could use the same criteria that put those records into the view to drive something else.

First, add an autonumber field to your table; I’ll refer to this as {Autonumber} below. Next, add a formula field. You didn’t mention what puts those records into that view, but let’s say that it’s a single select field named {Status} set to “In Queue”. In that case, the formula would look like this:

IF(Status = "In Queue", Autonumber, 0)

Assuming that records are set to “In Queue” (or however you’re marking them) in the same order that they’re created, this will output the record’s automatic number if it matches that status. Once you change the status to something else, it will drop out of that view, and the number returned by the formula will be 0.

This isn’t a perfect solution—the first record in the view wouldn’t start at 1 if you’ve got some records that have already fallen out of that view through previous processing—but it would get the job done without scripting. If you’d like something more precise, an automation-executed script could help clean up the numbering as records are updated, and also eliminate the need for the autonumber field. Message me directly if you’d like to explore that possibility.

How would I go about scripting something for this in 2023? 

Anonymous
Not applicable
Hi, Kate, here's an idea for assigning queue ordinals on a periodic basis. I apologize if the JavaScript is not very idiomatic -- I only use it for Airtable automations.
 

 

 

let table = base.getTable("<TABLE>");
let view = table.getView("<ORDERED VIEW>") //Create the filter/sort in a view and then lock it.
let query = await view.selectRecordsAsync({fields: []});
let ids = query.recordIds;

let list = [];

for (let i = 0; i < ids.length; i++) {
    list.push({
        id: ids[i],
        fields: {'Queue Position' : i + 1} //Create this field.
    })
};

const batchSize = 50; //The batch limit is given at airtable.com/developers/scripting/api/table.
for (let i = 0; i < list.length; i += batchSize) {
    let batch = list.slice(i, i + batchSize);
    await table.updateRecordsAsync(batch);
};