You almost had it! The problem seemed to be with your call to updateRecordAsync()
. You passed in the Field objects when the object needs to be “field names or IDs” as a String. The fastest thing I tried was pasting the Field names from lines 2 and 3 in (calling fromField.id
did not seem to do the trick).
One bug I noticed, while the code you have will copy a value to Field B if there’s not a value already there, it will copy a blank cell from Field A. This might be intentional, but if you don’t want Field B to be overwritten if nothing exists in Field A, edit the if
statement to include originalValue &&
.
Modified script is below.
let table = base.getTable("test");
let fromField = table.getField("fromField");
let toField = table.getField("destField");
let result = await table.selectRecordsAsync();
for (let record of result.records) {
let originalValue = record.getCellValue(fromField);
let destValue = record.getCellValue(toField);
// If nothing in Field B AND there was something in Field A
if(destValue !== null && originalValue){
//Copy the info
table.updateRecordAsync(record, {
//The keys here need to be Strings (fromField.id did not work for me)
"fromField": originalValue,
"destField": originalValue
});
}
}
You almost had it! The problem seemed to be with your call to updateRecordAsync()
. You passed in the Field objects when the object needs to be “field names or IDs” as a String. The fastest thing I tried was pasting the Field names from lines 2 and 3 in (calling fromField.id
did not seem to do the trick).
One bug I noticed, while the code you have will copy a value to Field B if there’s not a value already there, it will copy a blank cell from Field A. This might be intentional, but if you don’t want Field B to be overwritten if nothing exists in Field A, edit the if
statement to include originalValue &&
.
Modified script is below.
let table = base.getTable("test");
let fromField = table.getField("fromField");
let toField = table.getField("destField");
let result = await table.selectRecordsAsync();
for (let record of result.records) {
let originalValue = record.getCellValue(fromField);
let destValue = record.getCellValue(toField);
// If nothing in Field B AND there was something in Field A
if(destValue !== null && originalValue){
//Copy the info
table.updateRecordAsync(record, {
//The keys here need to be Strings (fromField.id did not work for me)
"fromField": originalValue,
"destField": originalValue
});
}
}
Note: if(destValue !== null && originalValue)
should probably be if(destValue === null && originalValue)
and you should add an await
before table.updateRecordAsync
.
You almost had it! The problem seemed to be with your call to updateRecordAsync()
. You passed in the Field objects when the object needs to be “field names or IDs” as a String. The fastest thing I tried was pasting the Field names from lines 2 and 3 in (calling fromField.id
did not seem to do the trick).
One bug I noticed, while the code you have will copy a value to Field B if there’s not a value already there, it will copy a blank cell from Field A. This might be intentional, but if you don’t want Field B to be overwritten if nothing exists in Field A, edit the if
statement to include originalValue &&
.
Modified script is below.
let table = base.getTable("test");
let fromField = table.getField("fromField");
let toField = table.getField("destField");
let result = await table.selectRecordsAsync();
for (let record of result.records) {
let originalValue = record.getCellValue(fromField);
let destValue = record.getCellValue(toField);
// If nothing in Field B AND there was something in Field A
if(destValue !== null && originalValue){
//Copy the info
table.updateRecordAsync(record, {
//The keys here need to be Strings (fromField.id did not work for me)
"fromField": originalValue,
"destField": originalValue
});
}
}
Thank you both @Matthew_Thomas & @Shrey_Banga