Oct 11, 2020 02:57 PM
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).
Solved! Go to Solution.
Oct 11, 2020 03:23 PM
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} );
Oct 11, 2020 03:23 PM
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} );
Oct 11, 2020 04:24 PM
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?
Oct 11, 2020 04:54 PM
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.
Oct 13, 2020 05:51 PM
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
Oct 13, 2020 06:02 PM
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.
Oct 13, 2020 06:53 PM
Oh no.
Silly question. I tried to make it a formula but it’s not liking that. Nor does it like QOH-1.
Oct 13, 2020 07:11 PM
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:
Oct 14, 2020 01:15 PM
That makes more sense, I missed that in your previous response. Thanks, again.