Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Sep 21, 2022 07:11 AM
Continuing the discussion from Creating new row entries from a long text:
Since this thread was closed and I’m facing a similar problem I was wondering if someone could help out.
I have a Long text field in my table, lets call it “Task Submission”, that I would like to create entries in another table from each new line of text, as shown in the image below.
Is there a Way to script this to run manually or automatically. I have an enterprise plan.
I need this because i need users to submit new tasks that need to be followed in another table.
thanks
Solved! Go to Solution.
Sep 22, 2022 02:17 PM
Hi,
change table1,2 and pri2,lnk2 names
const table=base.getTable('totals1')
const table2=base.getTable('totals2')
const query=await table.selectRecordsAsync({fields:['Task Submission']})
const arr=text=>text? text.split('"').join('').split(`\n`):[]
const newrow=r=>arr(r.getCellValue('Task Submission')).map(ln=>({fields:{'pri2':ln,'lnk2':[{id:r.id}]}}))
const crt=query.records.flatMap(newrow)
while (crt.length) await table2.createRecordsAsync(crt.splice(0,50))
Sep 21, 2022 01:41 PM
Are the task names known? Is there a maximum amount of tasks that can be entered?
It’s definitely possible to have some javascript code parse over the text field and transcribe returns into a linked field - the tricky part will be knowing what triggers words and numbers within the text field to be a task, and what separates one task from the next.
Sep 22, 2022 07:48 AM
The tasks are coming via a form submission, so they can be anything .
There is no Maximum but I don-t expect anything above 10.
Ideally, the script would be triggered via form submission or to run every day.
I’m sure this would be an easy task for someone with java script knowledge :slightly_smiling_face:
Sep 22, 2022 08:13 AM
I think What I would like to do is similar to this:
Linking Existing Records Using Automations | Airtable Support
Except I would like to create the new records (tasks) from an existing field. So each task is unique for each project
Sep 22, 2022 02:17 PM
Hi,
change table1,2 and pri2,lnk2 names
const table=base.getTable('totals1')
const table2=base.getTable('totals2')
const query=await table.selectRecordsAsync({fields:['Task Submission']})
const arr=text=>text? text.split('"').join('').split(`\n`):[]
const newrow=r=>arr(r.getCellValue('Task Submission')).map(ln=>({fields:{'pri2':ln,'lnk2':[{id:r.id}]}}))
const crt=query.records.flatMap(newrow)
while (crt.length) await table2.createRecordsAsync(crt.splice(0,50))
Oct 10, 2022 11:46 PM
Many thanks I will try it. just to be sure I got it…
I am guessing
“totals1” is the originator table with the “Task Submission” field from which lines will be converted to entries in the “totals2” table?
So I guess one of the “pri2” or the “link2” is the field in the destination table “totals2”, right? So what is the other one?
Maybe you copied this from another example and i am just a bit confused…
Thanks for clarifying
Thanks
Oct 11, 2022 12:57 AM
Hi,
nope, I’ve created it, just forget to rename tables. Pri and Lnk are primary and link fields of destination table.
Oct 27, 2022 02:28 AM
Thanks
FYI I found a work around that requires the use of automation and regex formula field. I will post it later
Dec 09, 2022 06:24 PM
Hey, can you post the workaround that you utilized? I have a similar problem to address.
Dec 15, 2022 07:43 AM
Yes, let me post the complete workaround in a while. But I can tell you it involves the Regex formula and an Automation