I have 2 tables that I am working with, one called Projects and the other called Tracking (which are essentially tasks). I created a button in the Projects table that will run the script below when pressed. I have 3 separate template views in the Tracking table: 1) Residential Diagnostic 2) Development Planning and 3) Internal. Whenever I run the script, it enters the tasks associated with the Internal view regardless of the Work Type I select. Can anyone tell me where I am going wrong?
// pick tables & views from your base here
let checklistTable = base.getTable(“Tracking”);
let projectsTable = base.getTable(“Projects”);
let allProjects = projectsTable.getView(“All Projects, all fields”);
// select an event to create a checklist for
let selectedEventRecord = await input.recordAsync(
“Choose a project to create checklist for”,
allProjects,
);
let workType = selectedEventRecord.getCellValue(‘Work Type Text’)
if (workType == “Residential Diagnostic”) {
let templateView = checklistTable.getView(“Residential Diagnostic”)
} else if (workType == “Development Planning”) {
let templateView = checklistTable.getView(‘Development Planning’)
} else (workType == “Internal”)
let templateView = checklistTable.getView(“Internal”)
output.text(${workType}.
);
if (selectedEventRecord) {
// load in all of of the tasks that our in our template
let templateQuery = await templateView.selectRecordsAsync();
let templateRecords = templateQuery.records;
// create new tasks based on the template
let recordsToCreate = templateRecords.map((templateRecord) => ({
fields: {
Task: templateRecord.getCellValue(“Task”),
Project: rselectedEventRecord], },
}));
await checklistTable.createRecordsAsync(recordsToCreate);
} else {
output.markdown("#You didn’t select a project!");
}
output.text(“Done!”);