Nov 05, 2021 08:46 AM
Hi guys :slightly_smiling_face:
Happy Friday!
I was trying to adapt one of the available scripts. However, I failed badly.
Opposite to the script I shared above, I’m using only two tables and in the main, I don’t want to create a template but I want to take a record (only a product name field) from the first table and incorporate it into the second table and assignee this record to a specific client (for that column, I’m using a single select feature). Those two tables are linked to each other by the product name column.
In other words, the first table is containing all our products, while the second table contains multiply of these duplicated records but each of these records is assigned to a different client. Each client’s view is tailored and depending on their profile we share only products that are relevant to their profile.
As our list of partners is growing, this task is becoming time-consuming as each time we need to perform it manually but with the sort of semi-automation, we could actually save plenty of time.
Would appreciate any help in this regard :slightly_smiling_face:
Nov 06, 2021 10:27 AM
Hi @Jakub_Szerszen - What you are describing sounds doable. A few thoughts:
Nov 07, 2021 01:20 AM
Thanks for your message.
It would be rather a bad solution for us due to the nature of our business. I don’t like when a base is stuck with dozen of tables. I like to keep each base with a maximum of 5-6 tables and as we cooperate with approximately 150 different partners you could imagine how messy a base could become. :slightly_smiling_face:
It’s purely a client’s decision. During the onboarding process, we’re interviewing a client and based on their answer we know how we want to tailor our portfolio for them.
We already have the solution in place (automation is running a script) when a new product is added to the main table. When a product matches certain conditions, the automation is adding a new product to our partners’ catalogues. However, the process is fully manual when we onboard a new client and need to build their view from scratch. Due to multiply records and a large number of our products, this is becoming a really time-consuming task. While with sort of semi-automation this task could be reduced to about 5 minutes.
I designed the example base
I’m working with. Our original base is more sophisticated but that should give you a good idea of the workflow.
Nov 18, 2021 04:13 AM
I think I found the root of the issue where my script is failing.
let productCatalogue = base.getTable('Product Catalogue');
let customers = base.getTable('Clients Roadmap&Portfolio');
let record = await input.recordAsync('Select a game', productCatalogue);
if (record) {
output.text(`You selected ${record.getCellValueAsString('name')}`);
output.text(`Adding ${record.getCellValueAsString('name')} to the client\s view ... please wait`);
let gameTitle = await productCatalogue.selectRecordsAsync();
let selectedGame = [];
for (let name of gameTitle.records) {
selectedGame.push(
{
fields: {
'For View': {name: 'Omega'},
'Game Name': {id: name.id}
}
}
)
await customers.createRecordsAsync(selectedGame);
output.text('Game added successfully to the client\s view')
}
} else {
output.text('Game cannot be added to the client\s view as it\s already available in the client\s view!!');
}
The script is failing on the ‘Game Name’ field and accordingly to the message displayed on airtable
Linked records field value must be an array of objects with property ‘id’ corresponding to linked record id.
Does anyone know what I should put in the line for Game Name? :pray:
Nov 18, 2021 09:14 AM
If Game Name is a linked field, the value you send needs to be an array of objects, not a single object, so this line:
'Game Name': {id: name.id}
should be:
'Game Name': [{id: name.id}]
(notice square brackets around the object. It doesn’t matter if you expect to link only a single record (1 object) - it must still be inside an array.
Nov 18, 2021 09:48 AM
thank you @JonathanBowen! The script is working now :blush:
Nov 19, 2021 06:05 AM
Hey @JonathanBowen
If could I ask you one more question. How could I implement into this script a conditional statement?
for (let name of gameTitle.records) {
selectedGame.push(
{
fields: {
'For View': {name: 'Omega'},
'Game Name': {id: name.id}
}
}
)
await customers.createRecordsAsync(selectedGame);
I’d like to add another line into this script for what we call a delivery. I’d like airtable to fetch information from the product catalogue and fill the delivery column depending on the product type.
I tried to use
'Delivery': if(type === “xxx”) { delivery = “ready to be released}
but then everything was underlined.
Nov 25, 2021 07:48 AM
@Jakub_Szerszen - you should be able to do this with a “ternary” expression:
Something like:
'Delivery': type === 'xxx' ? 'ready to be released' : 'some other value'