I have a script block that prompts the user for some information then creates a bunch or records that link records in two other tables.
I wanted to utilize the automation feature to further automate this process. Anytime a record in the “meeting” table is created, the automation script will trigger and create a record in an “attendance” table for each staff member listed in the “staff” table linked to the “meeting” record.
I’ve had this script work in the script block plenty. However, in migrating it to an automation script, I’m seeing a new error pop up.
I’ve confirmed that the “meeting” being passed from the trigger finds the record and then uses an object of the same format that the script block uses (script block asks the user to choose a record).
The createRecordsAsync function is throwing “Error: Request parameters failed validation.” I have a safeguard built in for the 50 record cap (in this testing instance, I’m only creating one record anyway).
Does anyone know of any additional restrictions on this function in the automation script environment? I’ve noticed some differences but that function seems to be the same.
SCRIPT BLOCK CODE
/* Get groups */
var groups = base.getTable("Staff").getField("Groups").options.choices.map(function(r){ return {
label:r.name,
value:r
} });
/* Pick a pre-defined group of staff (defined in the "Groups" field in "Staff" table as well as a view.) */
let group = await input.buttonsAsync('Which group of staff?', groups);
let TBLstaff = base.getTable("Staff");
let query = await TBLstaff.selectRecordsAsync({ sorts: s {field: "Name"} ], fields: r"Name","Groups"] });
let filtered = query.records.filter(function(r){
if(r.getCellValue("Groups")==undefined) {
return false;
}
else {
return r.getCellValue("Groups").map(function(r){return r.id}).includes(this.id);
}
}, group);
// output.table(filtered.map(function(r){return r.name})); // list chosen staff in a table
/* Pick meeting, but first choose how to filter options */
// let TBLmeetings = {};
// let whichMeeting = await input.buttonsAsync('Which meeting list?', t'Meetings w/ no attendance records', 'Any']);
// if (whichMeeting === 'Meetings w/ no attendance records') {
TBLmeetings = base.getTable("Meetings").getView("Meetings w/ no attendance records");
// } else {
// TBLmeetings = base.getTable("Meetings");
// }
let recordsList = await TBLmeetings.selectRecordsAsync({sorts: e{field: "Date"}, {field: "Type"}]});
let recordMeeting = await input.recordAsync('Pick a meeting', recordsList, {fields: "Name", "Date", "Type"]});
if (recordMeeting) {
output.text(`You picked ${recordMeeting.getCellValueAsString("Name")}`);
} else {
output.text("Opps! Nothing selected. There might not be any meetings without attendance records. Click \\"Run\\" to start over.");
return 0;
}
//throw JSON.stringify(recordMeeting);
/* Create links between each selected staff and the chosen meeting. */
var TBLattendance = base.getTable("Attendance");
var count = 0;
var recordsToSend = n];
var recordsCreated = ];
for( var i in filtered) {
recordsToSend.push(
{
fields: {
"Staff": filtered i]],
"Meeting":
}
}
);
while (count>=50) {
// Send every 50 records (if it were to ever have more than 50...limit for the multi create function)
await TBLattendance.createRecordsAsync(recordsToSend);
recordsCreated.push(recordsToSend);
recordsToSend = d];
count = 0;
}
}
await TBLattendance.createRecordsAsync(recordsToSend);
recordsCreated.push(recordsToSend);
output.table(recordsCreated);
AUTOMATION SCRIPT CODE
let inputConfig = input.config();
let TBLstaff = base.getTable("Staff");
let query = await TBLstaff.selectRecordsAsync({ sorts: s {field: "Name"} ], fields: r"Name","Groups"] });
let filtered = query.records.filter(function(r){
if(r.getCellValue("Groups")==undefined) {
return false;
}
else {
return r.getCellValue("Groups").map(function(r){return r.id}).includes(this.id);
}
}, inputConfig.group);
// Get Meeting Record
let meeting = undefined;
let meetingTable = base.getTable("Meetings");
let meetingQuery = await meetingTable.selectRecordsAsync();
for (let record of meetingQuery.records) {
if(record.id==inputConfig.meeting) {
meeting = record;
break;
}
}
/* Create links between each selected staff and the chosen meeting. */
var TBLattendance = base.getTable("Attendance");
var count = 0;
var recordsToSend = n];
var recordsCreated = ];
for( var i in filtered) {
recordsToSend.push(
{
fields: {
"Staff": filtered i]],
"Meeting":
}
}
);
while (count>=50) {
// Send every 50 records (if it were to ever have more than 50...limit for the multi create function)
await TBLattendance.createRecordsAsync(recordsToSend);
recordsCreated.push(recordsToSend);
recordsToSend = d];
count = 0;
}
}
let recordsCrtd = await TBLattendance.createRecordsAsync(recordsToSend);
output.set("recordsCrtd",recordsCrtd);
This is where the error is thrown.
let recordsCrtd = await TBLattendance.createRecordsAsync(recordsToSend);