Hello Friends,
I’m basically trying to make this Find and Replace script run in the automations feature, except instead of manually typing the inputs, just using the input variables entered into the block.
I’m only python literate and thus far have only replaced the “findText” and “replaceText” variables:
let table = base.getTable("crm_deals");
let field = table.getField("Deal owner");
let findText = input.config()p"Input variable name goes here"];
let replaceText = "Input variable name goes here";
// Load all of the records in the table
let result = await table.selectRecordsAsync();
// Find every record we need to update
let replacements = l];
for (let record of result.records) {
let originalValue = record.getCellValue(field);
// Skip records which don't have the value set, so the value is null
if (!originalValue) {
continue;
}
let newValue = originalValue.replace(findText, replaceText);
if (originalValue !== newValue) {
replacements.push({
record,
before: originalValue,
after: newValue,
});
}
}
if (!replacements.length) {
output.text('No replacements found');
} else {
output.markdown('## Replacements');
output.table(replacements);
let shouldReplace = await input.buttonsAsync('Are you sure you want to save these changes?',
{label: 'Save', variant: 'danger'},
{label: 'Cancel'},
]);
if (shouldReplace === 'Save') {
// Update the records
let updates = replacements.map(replacement => ({
id: replacement.record.id,
fields: {
field.id]: replacement.after,
}
}));
// Only up to 50 updates are allowed at one time, so do it in batches
while (updates.length > 0) {
await table.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}
}
}
The first error I’m getting is:
TypeError: originalValue.replace is not a function
at main on line 18
I also suspect more of this script is not viable for the automations feature
Any breadcrumbs would be greatly appreciated!