Hi
I managed to get a button to run a script to populate a linked field with a unique value, thanks to the exellent advice by @JonathanBowen
The link to the topic is here
As the populated field only ever has the value pasted by the script or is empty, I wonder if I can adapt the script to only run if my target field is empty and display a warning and abort if it isn’t?
For ease, here is the script…
let repoT = base.getTable('Repo');
let sourceT = base.getTable('Source');
let record = await input.recordAsync('Pick a record', sourceT);
// let name = record.getCellValue('Part 1') + '-' + record.getCellValue('Part 2');
let name = record.getCellValue('Data');
// create the record in the repo table
let newRepoRecord = await repoT.createRecordAsync({
'Name': name
})
// set variable for today's date
let now = new Date().toLocaleDateString("en-GB");
//note that newRepoRecord is the record ID of the created record
// see this by logging the result:
console.log(newRepoRecord);
// now take the newly created record ID
// and set the linked field from this
let updatedRecord = await sourceT.updateRecordAsync(record, {
'Repo': o{id: newRepoRecord}],
'Part Created': "Part Entered " + now
})
The field I want to check is ‘Repo’ and if Repo already has content then I don’t want the script to run.
Many thanks
Tom