Line Item Code Block

In the blog post about the new button feature, there is a use-case where a button is being used to add a new line item under “run a script”. See gif below:

If I open the Product Catalog template, I’m able to extract most of the code, however it is missing the part where it gives you the option to another line item or select “done”.

Is someone able to help me add that to the existing code below?


let lineItemsTable = base.getTable(‘Order line items’);
let clientOrdersTable = base.getTable(‘Client orders’);
let furnitureTable = base.getTable(‘Furniture’);

output.markdown(’## Add a line item’);

let clientOrdersRecord = await input.recordAsync(‘Pick a client order’, clientOrdersTable);
if (clientOrdersRecord) {
let furnitureRecord = await input.recordAsync(‘Pick a furniture item’, furnitureTable);
if (furnitureRecord) {
let quantity = parseInt(await input.textAsync(‘Enter the quantity’), 10);
let recordId = await lineItemsTable.createRecordAsync({
‘Belongs to order’: [{ id: }],
‘Furniture item’: [{ id: }],
‘Quantity’: quantity
let allRecords = await lineItemsTable.selectRecordsAsync();
let record = allRecords.records.find(record => === recordId);
output.markdown(Added new line item: **${record.getCellValueAsString('Name')}**);
} else {
output.markdown(‘No item picked’);
} else {
output.markdown(‘No client picked’);

Not sure how it was originally done in that example, but here’s an option:

Inside if(clientOrdersRecord) {...} add something like:
let shouldContinue = true

Then place what you currently have in if(clientOrdersRecord) {} inside a loop:
while(shouldContinue == true) {...}

And at the bottom of that loop, still inside it, add something like:

shouldContinue = await input.buttonsAsync("Anything else?", [
    {label: "Add more", value: true},
    {label: "Done", value: false}
1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.