Nov 05, 2024 05:45 PM - edited Nov 05, 2024 05:46 PM
I have an automation that is triggered when a user clicks a button in an interface. The automation is current set to simply create a new record in the underlying table, and fill in three fields:
user = should be the Name of the user who clicked the button. This is a "User" or "Collaborator" field in the underlying table. I have the user who clicks coming into the script using the input variable selector.
status = should be "Assigned" which is one of the possible values in the field, which is a single-select field.
string = "string is string" this is obviously a placeholder, but this is just a string.
Here's my code:
// Get the input variable
let inputConfig = input.config();
let userName = inputConfig.userName;
// Define the target table
let table = base.getTable('Table');
// Get the list of active collaborators in the base
let collaborators = base.activeCollaborators;
// Find the collaborator object that matches the userName
let assigneeCollaborator = collaborators.find(collaborator => collaborator.name === userName);
// Create a new record with the specified fields
await table.createRecordAsync({
'assignee': { assigneeCollaborator.name },
'phase': { name: 'Assigned' },
'string': 'string is string'
});
I had chatGPT o1-preview help with this, but continue to get errors related to the "assignee" field. After some iteration I got the "phase" field to work with the above, but have tried various version of the above, both simpler and more complex and cannot get the "assignee" field to accept the name of the person. If I output is with console.log, it looks just fine.
Any ideas what I can do here?
Solved! Go to Solution.
Nov 05, 2024 05:58 PM
Try changing your input variable to be the user ID instead:
And then use this:
// Get the input variable
let {userId} = input.config()
// Define the target table
let table = base.getTable('Table');
// Create a new record with the specified fields
await table.createRecordAsync({
'Assignee': {id: userId},
});
If your User field allows for multiple users, you'll need to use the following for the record creation bit:
// Create a new record with the specified fields
await table.createRecordAsync({
'Assignee': [{id: userId}],
});
Nov 05, 2024 05:58 PM
Try changing your input variable to be the user ID instead:
And then use this:
// Get the input variable
let {userId} = input.config()
// Define the target table
let table = base.getTable('Table');
// Create a new record with the specified fields
await table.createRecordAsync({
'Assignee': {id: userId},
});
If your User field allows for multiple users, you'll need to use the following for the record creation bit:
// Create a new record with the specified fields
await table.createRecordAsync({
'Assignee': [{id: userId}],
});
Nov 05, 2024 06:38 PM
That worked great!
I think one problem was just that I did not understand using ID as input and even as the value in the field would work to actually put the name when looking at the table, so I just avoided it. Thank you for making me try it!