Help

Re: Use Button to Decrement Cell Quantity

Solved
Jump to Solution
2547 0
cancel
Showing results for 
Search instead for 
Did you mean: 
wjb
6 - Interface Innovator
6 - Interface Innovator

Hey all. I did some searching through the forum and support but don’t see this scenario. I’d like to use a Button Field to decrement (remove) one unit another cell (Quantity on Hand).

  1. The process would be to scan QR on a label made by page designer.
  2. On mobile you’d tap the button, REMOVE 1
  3. Button action subtracts one from the QOH cell of that record.

image

1 Solution

Accepted Solutions
ScottWorld
18 - Pluto
18 - Pluto

You could do this by having your button trigger a script.

I’m just in the early, baby, beginning stages of learning JavaScript myself, so here is a script that I just cobbled together right now. This script actually works, but I am 1,000% sure that this can be optimized significantly better than this.

This is my very first JavaScript script that I’ve ever written! :slightly_smiling_face: This should work for now, until someone helps optimize this code better:

let myTable = base.getTable('Tool Library');
let myRecord = await input.recordAsync('Select a record', myTable);
let myField = myTable.getField('QOH');
var newNumber = myRecord.getCellValue(myField) - 1;
myTable.updateRecordAsync( myRecord, { [myField.id]: newNumber} );

See Solution in Thread

8 Replies 8
ScottWorld
18 - Pluto
18 - Pluto

You could do this by having your button trigger a script.

I’m just in the early, baby, beginning stages of learning JavaScript myself, so here is a script that I just cobbled together right now. This script actually works, but I am 1,000% sure that this can be optimized significantly better than this.

This is my very first JavaScript script that I’ve ever written! :slightly_smiling_face: This should work for now, until someone helps optimize this code better:

let myTable = base.getTable('Tool Library');
let myRecord = await input.recordAsync('Select a record', myTable);
let myField = myTable.getField('QOH');
var newNumber = myRecord.getCellValue(myField) - 1;
myTable.updateRecordAsync( myRecord, { [myField.id]: newNumber} );
wjb
6 - Interface Innovator
6 - Interface Innovator

Holy moly that was a fast and perfect answer! This is fantastic - many thanks!

Edit - It worked perfectly on desktop and when I went to try it on iOS I got an error because Apps don’t work there yet - not something you @ScottWorld could change just relaying it for others finding this.

Hopefully, this changes soon?

IMG_0227.PNG

There’s actually a workaround for this on mobile, which would be to use an Airtable automation instead.

However, you wouldn’t be able to use a button field anymore, because for some odd reason, Airtable has decided that buttons and automations are 2 separate things, and that buttons can’t trigger automations. Makes no sense. :man_shrugging:

So, instead of using a button, you’d have to use a checkbox field instead. Whenever you check the checkbox, the automation would decrease the number by 1. And you can even make your automation clear out the checkbox after you check it, so it’s ready to go again for checking again.

In fact, you wouldn’t even need a custom JavaScript to do this. You would just need a formula field that results in your current number field minus 1. Then, just have your automation set your number field to this formula field. And then have your automation clear out the checkbox field.

wjb
6 - Interface Innovator
6 - Interface Innovator

Very smart. I’m new to apps and automations but man does it seem like there’s a ton of needed workarounds. Hopeful some of these silly things get fixed soon.

Appreciate the fast helpful solutions though!

Justin

Ha! I wouldn’t hold your breath, LOL. I have a list of 250+ bugs, problems, inconsistencies, and nuisances in Airtable that have yet to be fixed, despite people clamoring for them for years. In my personal opinion, the team behind Airtable is not very detail-oriented nor do they care very much about the user experience. They roll out “big features” to appease their VC funders, but they have nobody focusing on the actual day-to-day usability of the product nor the “little details” of the product, But that’s just my opinion. I’d love to be proven wrong.

@Taylor_Savage

wjb
6 - Interface Innovator
6 - Interface Innovator

Oh no.

Silly question. I tried to make it a formula but it’s not liking that. Nor does it like QOH-1.

image

I meant that you actually need to create an actual formula field in your table, and then reference that formula field in your action step when you’re updating your number field.

Action steps themselves don’t support formulas, but it would be cool if they did!

Integromat’s action steps (and trigger steps) DO support formulas, which is one of the top 10 reasons I love that platform so much.

Would be awesome if Airtable “borrowed” that feature from them. :stuck_out_tongue_closed_eyes:

wjb
6 - Interface Innovator
6 - Interface Innovator

That makes more sense, I missed that in your previous response. Thanks, again.