Skip to main content

Hi everyone!


There’s a seemingly basic problem that’s driving me crazy: I have an automation that triggers a script to create a few records. When creating these records, I need to set the value of a single-select field. It works well when I assign a basic string to the variable, but fails when I use getCellValueAsString ! Anything I’m missing? (console.log on the result of getCellValueAsString shows the correct result and typeOf on the variable shows indeed “string”)


let tableMapOuvrages = base.getTable("Map ouvrages");
let tableTaches = base.getTable("Taches");
let inputConfig = input.config(); //get the variables from previous steps

let mapOuvrages = await tableMapOuvrages.selectRecordsAsync({
fields: "Ouvrage","Groupe ouvrage"]
});

for (let itemInMap of mapOuvrages.records) {

let basicString = "Livraison menuiseries";
let stringOuvrage = itemInMap.getCellValueAsString("Ouvrage");
console.log(stringOuvrage ); // this shows "Livraison menuiseries"
console.log(stringOuvrage ); // this shows "string"

// the "temp" field below is a single-select
let tache = await tableTaches.createRecordAsync({
"temp": {name: basicString } // This version works
// "temp": {name: stringOuvrage } // this version doesn't work !

});

}

Welcome to the Airtable community!


What error messages do you get when it does not work? Can you share a screen shot?


Could one of the single select choices have a hidden trailing space or other hard-to-see difference?

What happens if you add these lines …



console.log(stringOuvrage );
console.log(basicString );
if (basicString === stringOuvrage) {
console.log(`${stringOuvrage} and ${basicString} match`)
} else {
console.log(`${stringOuvrage} and ${basicString} do NOT match`)
}


The script you posted doesn’t match you description of what is happening. The script you posted is missing the type of.


Reply