Scripting: Multiple Linked Records in One Record

Hi,

I’m developing a script for a client and their water store, allowing them to checkout multiple products and log the transaction in AirTable. I still haven’t played around with this yet, but I thought I’d ask the communitty: how do you create multiple linked records for a single record?

I thought about saving the record IDs of the inventory items to an array, and then using a forloop to update the record: but I imagine that would erase the previous link. I’m thinking that I could do this by concatenating all of the record IDs into a single string, and then using that variable when updating the record.

I’ll report back here when I’ve made some progress, would love to hear your thoughts.

Resolved, this was a LOT easier than I was expecting.
The answer: create an object that contains only one property, “id”, and then push that object to an array.
When creating a record using createRecordAsync, pass that object in as a variable and you’re good to go.

For some context, this is a snippet of a larger script for a local water store in my neighborhood.

var item = {
					Num: item_record.getCellValue("Item #"),
					Product: item_record.getCellValueAsString("Product"),
					Type: item_record.getCellValueAsString("Type"),
					Price: item_record.getCellValue("Price"),
					Quantity_Requesting:  Number(temp),
					Subtotal: Number(temp) * Number(item_record.getCellValue("Price")),
					OnHand: item_record.getCellValue("Quantity On Hand"),
				};

				var recID = {id: item_record.getCellValueAsString("Record ID")}
				cart.push(item);
				inventoryRecID.push(recID);
                let Transtable = base.getTable("Transactions");
				var inventoryArray = inventoryRecID.join();
				let TransId = await Transtable.createRecordAsync({
					"Cash In": cashin,
					"Inventory": inventoryRecID,
					"Deposit": gallon_deposit,
					"Withdraw": gallon_withdraw,
					
				});
1 Like

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