I’m not a programmer, I’m trying to update a record based on the conditions selected. I’m battling to understand the ‘await’ function.
I believe it’s a promise and that it splits the code until the conditions are fulfilled? I kept getting an error if I put the await inside the if conditions.
I’ve re-written this a few hundred times and tried looking up what other people have done and now I’m throwing in the towel.
Below is the full script, any guidance would be hugely appreciated.
// Change this name to use a different table
let table = base.getTable("Game Tracker");
// Prompt the user to pick a record
// If this script is run from a button field, this will use the button's record instead.
let record = await input.recordAsync('Select a record to use', table);
let seats = record.getCellValue("Employees");
let segmentSize;
await table.updateRecordAsync(record, {"Segment": segmentSize})
if(seats) {
if(seats > 300) {
segmentSize = "Enterprise";
} else if (seats < 300 && seats > 149) {
segmentSize = "Upper Mid Market";
} else if (seats < 150 && seats > 49) {
segmentSize = "Lower Mid Market";
} else if (seats < 50 && seats > 9) {
segmentSize = "SMB";
} else {
segmentSize = "Indies"
}
}
output.text(`The segment for ${record.name} has ${seats} is ${record.getCellValue("Segment")}`)
the output is usually ‘Null’ for the segment.
