// Load the Airtable scripting environment
let assessmentTable = base.getTable("Assessment converter");
let submissionsTable = base.getTable("Submissions test");
let query = await assessmentTable.selectRecordsAsync();
let fieldName = "Output";
// Iterate over all records in the "Assessment converter" table
for (let record of query.records) {
// Get the JSON data from the 'Output' field
let output = record.getCellValue(fieldName);
// Debugging: Log the output to check its content
console.log("Output:", output);
try {
// Parse the JSON data
let jsonData = JSON.parse(output);
// Debugging: Log the parsed JSON data
console.log("Parsed JSON data:", jsonData);
// Iterate over the parsed JSON data
for (let item of jsonData) {
// Prepare the data for the 'Submissions test' table
let submissionData = {
"Question number raw": item["question number"] || "",
"Question raw": item["question"] || "",
"Marks for question raw": item["marks for question"] || "",
"Student answer raw": item["student answer"] || ""
};
// Debugging: Log the submission data
console.log("Submission data:", submissionData);
// Create a new record in the 'Submissions test' table
await submissionsTable.createRecordAsync(submissionData);
}
} catch (e) {
console.error("Error parsing JSON data:", e);
}
}
I've tried to troubleshoot this multiple times but can't seem to figure out what the issue is. Assistance would be greatly appreciated. Thanks