Thanks for your advice @Alexey_Gusev.
As a non-technical user I feel challenged by this. I inserted the four lines of code 1:1 into the respective section of the code but receive a new error:
ERROR
SyntaxError: Invalid or unexpected token
on line 1
at o on line 1
at Generator._invoke on line 1
at Generator.F.forEach.u.<computed> [as next] on line 1
at t on line 1
at a on line 1
on line 1
on line 1
The cause is probably as simple as a variable, bracket, comma or semicolon…
I’m copying the entire code below, it’s the original script plus four fields I added manually.
// Create settings
let settings = input.config({
title: 'Create records for multiple templates',
description: 'This script will create records in a child table that link back to a parent record and are based on the template records that correspond to the parent record type',
items: [
input.config.table('parentTable', {
label: 'Parent table',
description: 'Table from which you need to create template records (ex: Projects; Campaigns)'
}),
input.config.table('typeTable', {
label: 'Type table',
description: 'Reference table with records for each template type (ex: Project categories; Campaign sizes)'
}),
input.config.table('templateTable', {
label: 'Template table',
description: 'Reference table with records for each template record and a linked record to the Type Table (ex: Task templates; Activity templates)'
}),
input.config.table('childTable', {
label: 'Child table',
description: 'Table in which you need to create records based on the type linked record (ex: Tasks; Activities)'
}),
input.config.field('parentType', {
parentTable: 'parentTable',
label: 'Parent type',
description: 'Linked record in parent table to type table (ex: Project type; Campaign size)'
}),
input.config.field('templateType', {
parentTable: 'templateTable',
label: 'Template type',
description: 'Linked record in template table to Type Table (ex: Project type; Campaign size)'
}),
input.config.field('childFieldInTemplate', {
parentTable: 'templateTable',
label: 'Child field in template table',
description: 'Text field in template table to indicate name of record (ex: Task name; Activity name)'
}),
input.config.field('templateOrder', {
parentTable: 'templateTable',
label: 'Template record order',
description: 'Number field in template table to indicate order in which records should be executed (ex: Task order; Activity order)'
}),
input.config.field('childOrder', {
parentTable: 'childTable',
label: 'Child record order',
description: 'Number field in child table to indicate order in which records should be executed (ex: Task order; Activity order)'
}),
input.config.field('childNameInChild', {
parentTable: 'childTable',
label: 'Child name',
description: 'Text field in child table to indicate name of record (ex: Task name; Activity name)'
}),
input.config.field('parentFieldInChild', {
parentTable: 'childTable',
label: 'Parent field in child table',
description: 'Linked record in child table to indicate related parent record (ex: Project; Campaign)'
})
],
})
// Define tables from script settings
let parentTable = settings.parentTable;
let typesTable = settings.typeTable;
let childTable = settings.childTable;
let templateTable = settings.templateTable;
if ([typesTable, childTable, templateTable].indexOf(parentTable) != -1 ||
[childTable, templateTable, parentTable].indexOf(typesTable) != -1 ||
[templateTable, parentTable, typesTable].indexOf(childTable) != -1) {
throw new Error("Parent table, type table, template table, and child table should all be different tables.")
}
// Define fields from script settings
let childFieldInTemplate = settings.childFieldInTemplate;
let childNameInChild = settings.childNameInChild;
let childOrder = settings.childOrder;
let templateOrder = settings.templateOrder;
let templateType = settings.templateType;
let parentFieldInChild = settings.parentFieldInChild;
// Select parent record to create child records & select type
let selectedEvent = await input.recordAsync('Choose record', parentTable);
while (!selectedEvent) {
output.text('You must select a record.');
selectedEvent = await input.recordAsync('Choose record', parentTable);
}
let parentType = selectedEvent.getCellValue(settings.parentType);
// Look up template records
let typesQuery = await templateTable.selectRecordsAsync();
let typesRecords = typesQuery.records;
// Filter the template records to match the selected type & add the parent ID to the map
let types = typesRecords.map(c => ({
'child': [c],
'childName': c.getCellValue(childFieldInTemplate),
'templateTypes': c.getCellValue(templateType).map(x => x.id),
'templateOrder': c.getCellValue(templateOrder),
'templateDate':c.getCellValue('Date'),
'templateDeparture':c.getCellValue('Departure'),
'templateService':c.getCellValue('Service'),
'templateDays':c.getCellValue('Days')
// Add additional template fields here and in section below using format below.
// Field names within c.getCellValue parentheticals should match field names in template table
// 'templatePhase':c.getCellValue('Phase'),
// 'templateDays': c.getCellValue('Days')
})).filter(x => x.templateTypes.includes(parentType[0].id))
// Create the child records and sort them so that they are in order
let createRecords = types.map(c => ({
fields: {
[childNameInChild.name]: c.childName,
[parentFieldInChild.name]: [selectedEvent],
[childOrder.name]: c.templateOrder,
'Date':c.templateDate,
'Departure':c.templateDeparture,
'Service':c.templateService,
'Days':c.templateDays
// Add additional template fields here and in section above using format below.
// Field names on the left should match field names in child table.
// Field names on the right following c. should match names created in section above that starts at line 72.
// 'Phase':c.templatePhase,
// 'Days': c.templateDays
}
})).sort((a, b) => {
return a.fields[childOrder] - b.fields[childOrder];
});
if (selectedEvent) {
// create records in batches of 50
output.inspect(createRecords)
output.text(’=========’)
output.inspect(typesRecords)
let debug=await input.buttonsAsync(‘press to’,[‘continue’])
while (createRecords.length > 0) {
await childTable.createRecordsAsync(createRecords.slice(0, 50));
createRecords = createRecords.slice(50);
}
}
output.text('Done!');
The template’s table four manual fields, the date field throws the error.
Single expanded record’s relevant fields.
The child table where the records are created.
Thanks for helping out a JavaScript dummy. 