Help

Re: Use a "button" field to enter a value for that single record

Solved
Jump to Solution
4802 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Mittens
5 - Automation Enthusiast
5 - Automation Enthusiast

Howdy,

I have a database that deals with inventory for serialized items. For each item, I need to know when they have been found to be in-stock. Here’s what my setup looks like today:

  • Records are items uniquely identified by a serial number
  • One link-to field is Inv_Seen In which collects values each month that that item has been present for. As an example, one record will have been “Seen In: 2022-06” which means it was seen in June 2022. I manually type “2022-06” for each item.
  • This setup is working fine, but requires a lot of typing the same exact thing over and over again

220728

Here’s my “dream” setup that I’d like help writing a script to achieve:

  • Records are uniquely identified by a serial number
  • One link-to field is Inv_Seen In and collects values… BUT…
  • …There is ALSO a button field called Inv_In Stock? whose action is “Run Script”. That script will populate Inv_Seen In with “2022-06” (or whatever the month currently is. I am a-okay hardcoding the month value in the script.) for just that single record for which I clicked the button.

The block for me writing the script is that I’m not sure how to pass the current record from the button field to the script. The documentation I have found so far queries for a set of records, but I have not found how to simply act on the single record that belongs to the button.

Could someone post documentation or an example to use the “button” field to pass the current record ID to a script to append text to a field for that single record?

Thank you,
–Mitch

1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

let record = await input.recordAsync("Pick a record", table)

Here is the documentation.

See Solution in Thread

5 Replies 5
Russell_Findlay
8 - Airtable Astronomer
8 - Airtable Astronomer

Could you just use an automation (coupled with a formula field

1: field with Dateformat(Now) - and choose the format that your inventory stock check dates are in

2: trigger based on button which enters the existing data PLUS this field into the seen linked record field.

Hi @Russell_Findlay thank you for looking at my question.

Per your suggestion, I have created a new field that writes the “inventory check dates” in my preferred format. These are now sitting in waiting in a formula field called Inv_Slug.

image

I see you also suggest “2: trigger based on button…” - this is precisely what I want to do! Do you have any hints on how I might be able to do that?

(At the moment, I don’t see how to connect a button to an automation. I also don’t know how to connect a button to a script to act on just the one record that the button originated from. Moreover, I understand how I could make ALL items in a certain view as “inventory seen”. What I don’t yet understand is how to selectively do one item by clicking the one button from the button field.)

kuovonne
18 - Pluto
18 - Pluto

let record = await input.recordAsync("Pick a record", table)

Here is the documentation.

Russell_Findlay
8 - Airtable Astronomer
8 - Airtable Astronomer

You are now in safe hands - BUT seeing your button as a check box made me think

if scripting isn’t your thing … here is a hack of a no code alternative… using a check box rather than a button

1: Have a table called Months - this will be your INV seen in related link
image

2: Your inventory table should have these fields

image

Done is your check box (spoof of a button)
Last modified is just the last modified time of your done field
Last Checked is your friednly date format of the last modified field to create your Inv seen in records)

An automation that triggers when Last Modified is changed (optional - only when it is checked as a condition)

with two optional actions - one for when there is already data in the INvSeen in Field and one for when it is blank (so that it adds to the linked records rather than overwrites them)

image

image

It may take a few seconds to work

Hope that helps

Mittens
5 - Automation Enthusiast
5 - Automation Enthusiast

@Russell_Findlay Thank you for the “no code” option. Your screenshots were informative. At the moment, I’m going to try to stick-things-out with a script though… Wish me luck.

@kuovonne Ah hah! I cannot believe I repeatedly overlooked that portion of the documentation.There’s even an example that served as my starting off point. Thank you for your help; your response is what finally made it click for me.

Here’s my existing script that I am running with. Thanks all!


// Script to add "list items" to a list with existing items via a button field button

/* Get the record */

let table = base.getTable("Items");

let view = table.getView("Inventory");

let record = await input.recordAsync("Pick a record", view); // This accepts the button field button, horray!

/* Get the intended month */

const new_month = [];

let month_table = base.getTable("Months");

let month_view = inv_table.getView("All");

new_month.push(await input.recordAsync("Pick the month", month_view)); // I still need to find a way to have this picked by the script

/* Merge with existing months */

const existing_months = record.getCellValue("Inv_Seen In");

const months = new_month.concat(existing_months)

/* Execute */

await table.updateRecordAsync(record,{"Inv_Seen In": months})