Hi,
I have a track table and an album table.
When an album status changes to “ready for release”, I have an automation that finds tracks that belong to that album, then feeds those IDs to a script.
The script should do the following:
- Based on the track info, populate an “internal number” (works fine)
- Do another query on those same ids, but sort by this newly added “internal number” and another existing field, then update track numbers in sequence.
It appears that the new search does not return results sorted according to what is specified in my script.
Any ideas why?
I also have this script separately from automations, where I go and pick an album manually, and that one works 100%. I’m not sure why the same thing in automations isn’t behaving correctly.
// Sort by:
// - album (fieldToRank1),
// - the newly added main track number (fieldToRank2), and
// - nesting sort position (fieldToRank3)
// to create and inject Harvest track number in each track.
var harvestTrackNumber = 0;
saRecords = await tracks.selectRecordsAsync({
recordIds: ids,
sorts:[
{field:fieldToRank1, direction:"asc"},
{field:fieldToRank2, direction:"asc"},
{field:fieldToRank3, direction:"asc"},
],
fields: [
"Master ID",
"SourceAudio ID",
"Track Number",
"INTERNAL: master track no",
"Album Code",
"Nesting Sort Position",
"INTERNAL: Harvest no"],
});
for (let record of saRecords.records){
harvestTrackNumber ++;
// Update selected field with the new track number
await tracks.updateRecordAsync(record.id, {"INTERNAL: Harvest no":harvestTrackNumber,});
}```