Hi there, I’m trying to create an airtable automation script whereby it takes in the Full name of a record and changes only the first letter into uppercase (upper caps). This is my code, I can’t seem to get it to work, can anyone help me with this?
let table = base.getTable("Training Masterlist");
// Use the correct field name that maps to the automation's Record ID
let recordId = input.config().AirtableRecordID; // Correct this if it's named differently
// Ensure that the recordId exists, if not, log an error
if (!recordId) {
throw new Error("Record ID is undefined.");
}
// Field name
let fullNameField = "Full Name (As in NRIC)";
// Fetch the record that triggered the automation
let record = await table.selectRecordAsync(recordId);
// Get the current value of the "Full Name (As in NRIC)" field
let fullName = record.getCellValue(fullNameField);
if (fullName) {
// Convert the full name to the desired format
let formattedName = fullName
.split(" ") // Split the name into words by spaces
.map(word => {
// Capitalize the first letter and make the rest lowercase
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
})
.join(" "); // Join the words back together
// Update the record with the new formatted name
await table.updateRecordAsync(recordId, {
>fullNameField]: formattedName
});
}