Last active
June 22, 2023 02:49
-
-
Save SamCed/ebf59a1a063fa43e94a25a9c41c14d56 to your computer and use it in GitHub Desktop.
Link Fields based on matches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Copy Values to a linked field | |
//Declare tables | |
var activeTbl = base.getTable("The table where you need to copy values to"); | |
var linkTbl = base.getTable("Table that contains your linked records"); | |
//Declare queries | |
var activeQry = await activeTbl.selectRecordsAsync(); | |
var linkQry = await linkTbl.selectRecordsAsync(); | |
//Loop through your active table records | |
for(let activeRec of activeQry.records){ | |
//Declare field in the active table you'd like to match | |
let actField = activeRec.getCellValueAsString("Field you want to match") //If a Number, use getCellValue instead of getCellValueAsString | |
//Declare Variable that will represent your new value | |
let updRec = undefined; | |
//Loop through the records in the link table | |
for(let linkRec of linkQry.records){ | |
//Declare field in the link table you want to match to | |
let linkField = linkRec.getCellValueAsString("Field you want to match to") //Whether getCellValue/getCellValueAsString is used should be the same as above | |
//Match the records by that field | |
if(actField == linkField){ | |
updRec = linkRec.id; | |
break; | |
} | |
} | |
//Update Records | |
if(updRec !== undefined){ | |
await activeTbl.updateRecordAsync(activeRec, { | |
"The linked field": [{id:updRec}] //The field type must be a linked field | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment