Help

Generate QR - help with a script

1340 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Mariusz_S
7 - App Architect
7 - App Architect

I’m using a script that generates a QR code as an attachment.

Here’s the structure.
d11f86c657f7abece1e59c4ef773d4a27432f54b.png
The script that I use (shared by someone here) will:
1. Generate QR codes for the record as an attachment.
2. If this record already has an attachment, skip it.

// Change the names of this table/fields according to your base.
let submissionsTable = base.getTable('⚙️ Realizacja');
let urlField = submissionsTable.getField('barcodes4.me [URL]');
let attachmentField = submissionsTable.getField('QR Customer');

let submissionsQuery = await submissionsTable.selectRecordsAsync();
let updates = [];
for (let record of submissionsQuery.records) {
    let url = record.getCellValue(urlField);
    let attachments = record.getCellValue(attachmentField);

    // If this record already has an attachment, skip it.
    if (attachments !== null) {
        continue;
    }

    // Otherwise, attach the image at the URL.
    updates.push({
        id: record.id,
        fields: {
            [attachmentField.id]: [{url: url}]
        }
    });
}

// Update records in batches of 50.
while (updates.length > 0) {
    await submissionsTable.updateRecordsAsync(updates.slice(0, 50));
    updates = updates.slice(50);
}

How to modify the script so it would only generate the QR for a specific record and not all?

I get a hint in AT but entirely sure how to do it.

Record from button field was not used

This script did not use the record from the button field. To use a record from a button field, call input.recordAsync in your script.

Don't show again
1 Reply 1

The most efficient end elegant way to encourage script to apply logic conditionally is to read the data from a view, not a table. If the view includes only the records you need to process, you needn’t write any logic testing for this condition. The code is simpler, the processing is faster (because you’re only reading the records that matter), and the system is more agile (i.e., filters can change on a dime; code not so much).