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.
Dec 19, 2022 06:07 PM - edited Jan 20, 2023 08:39 AM
I was actually able to figure it out using a script.
Dec 20, 2022 08:01 AM
Here is a different approach to generating multiple entries in a new field (this field is in a new table) from a single field.
Table setup:
Table 1
as you can see each new line in the "Entry" field will be a new entry on table 2
Table 2
In this setup for each new entry in table 1 each new line in the "Entry_field" will generate a new entry in table 2 via the Regex formula fiedl and an automation.
The automation is set up as follows:
There are some requirements for this to work:
Maybe its not so clear but but happy to give feedback
Dec 21, 2022 05:32 AM
Feel free to share!
Jan 20, 2023 06:14 AM
To come back to this if I want to just do this for a record identified in an automation step, I would need to invoke the input config
How would I include that in this script example?
Many Thanks
Jan 20, 2023 08:57 AM - edited Jan 20, 2023 11:57 AM
Here is the full script I ended up using (in case someone else needs it), put together by a few helpful examples across the community board.
let inputData = input.config();
let musicianData = inputData.musicianData;
let presenterData = inputData.presenterData;
let installationData = inputData.installationData;
let subRecordId = inputData.subRecordId;
let parseMP = "";
const mpTable = base.getTable("Musicians/Presenters");
const installTable = base.getTable("Installation Artists");
//checks to see which data we're using
if (presenterData) {
parseMP = presenterData
}
else if (musicianData) {
parseMP = musicianData
}
else {}
if(parseMP){
//split data in separate arrays/lines for each record
console.log(`Processing musician/presenter data...`)
let getRecordCount = parseMP.split("\n").length -1;
for (let i = 0; i < getRecordCount; i++) {
let array = parseMP.split("\n");
let line = array[0+i];
let [perfName, legName, email, startTime, endTime, fee] = line.split(',');
console.log(`
Performer: ${perfName}
Legal Name: ${legName}
Email: ${email}
Start Time: ${startTime}
End Time: ${endTime}
Fee: ${fee}`)
//create record
let artistRecord = await mpTable.createRecordAsync({
"Performance": perfName,
"Legal Name": legName,
"Email": email,
"Start Time": startTime,
"End Time": endTime,
"text_Fee": fee,
"Linked Submission": [{id:subRecordId}],
"Registration Status": {name: "Unregistered"}
})
console.log(`Records created`)
}
}
if(installationData){
console.log(`Processing installation artist data... `)
let getRecordCount = installationData.split("\n").length -1;
for (let i = 0; i < getRecordCount; i++) {
let array = installationData.split("\n");
let line = array[0+i];
let [installName, legName, email, fee] = line.split(',');
console.log(`
Install: ${installName}
Legal Name: ${legName}
Email: ${email}
Fee: ${fee}`)
//create record
let artistRecord = await installTable.createRecordAsync({
"Installation": installName,
"Legal Name": legName,
"Email": email,
"text_Fee": fee,
"Linked Submission": [{id:subRecordId}],
"Registration Status": {name: "Unregistered"}
})
console.log(`Record created`)
}
}
For context, this takes a booking submission for Musicians, Workshop Presenters, and Installation Artists from a Jotform submission, and turns it into records in the relevant tables. I can post screenshots of the database setup if anyone needs it.
let inputData = input.config();
let musicianData = inputData.musicianData;
let presenterData = inputData.presenterData;
let installationData = inputData.installationData;
let subRecordId = inputData.subRecordId;
In your example, I would change the variable name to selectedRecords (remove the space, use camel case if you want multiple words in one variable assignment).
Note that you can only call input.config() once. If you only have this one variable in your code, you can get away with doing something like
let selectedRecords = input.config().selectedRecords
but if you anticipate using more than one variable from earlier in the automation, you'll need to assign input.config() to it's own variable, then assign each new variable using that. This is what I did in my script, input.config() became inputData, and I brought each variable into the script by doing "xyz = inputData.xyz"
Please note: I am not that experienced with Javascript. I may not be using best practices in my script. If anyone else would like to chime in with any suggestions, edits, or conventions they'd like to share, by all means.