And here’s the script that will sort the attachments in alphabetical order for all records in a view.
Note: Make sure that all uploads are done before running the script or you could get unexpected results.
let table = await input.tableAsync("Select a table");
let view = await input.viewAsync("Select a view", table);
let field = await input.fieldAsync("Pick an attachment field", table);
let queryResult = await view.selectRecordsAsync();
let records = queryResult.records;
for (let record of records) {
let attachmentData = record.getCellValue(field.name);
if (attachmentData && attachmentData.length > 1) {
let newAttachmentData = sortArray(attachmentData);
await table.updateRecordAsync(record.id, {
[field.name]: newAttachmentData,
});
}
}
function sortArray (attachmentArray) {
return attachmentArray.sort((a,b) => {
return a.filename.localeCompare(b.filename);
})
}
If this answers your question, please mark this post as the solution. Otherwise, could you please give a bit more details and a screen capture?