Possible to pass a string into a function

I’m trying pass a string as a field - which I’m pretty sure I’ve seen @kuovonne explain someone else that it’s possible.

const mainCur = base.getTable("Contacts").getView("Currency");
const mainCurMatchField = 'Currency name'

const mainCurrencyConversion = async (tableView, matchField) => {
    let selectRecords, gbp, eur, usd

    selectRecords = await tableView.selectRecordsAsync();
    [gbp, eur, usd] = await getConversion('test')

    for (let record of selectRecords.records){
        console.log(record.getCellValue(matchField))
       
    }
    
};

await mainCurrencyConversion(mainCur, mainCurMatchField)

I’m trying to get record.getCellValue(matchField) to use ‘Currency name’ as field name. I’ve tried to wrapped it in {}, but so far I’ve been out of luck.

Is this possible or is it me who got this wrong?

I don’t see where matchField has been defined.

1 Like

Hi @Kim_Trager - I think you are on the right lines. I know this isn’t you exact scenario, but this works for me:

let table = base.getTable('Table 1');
let query = await table.selectRecordsAsync();

let myField = 'Name of Person';

let results = (field) => {
    for (let record of query.records) {
        console.log(record.getCellValue('Name of Person'))
        console.log(record.getCellValue(field))
    }
}

results(myField);

based on this table:

So referring to the field by its name explicitly or by passing its name through as an argument in the function gives me the same output.

1 Like

Hi @JonathanBowen - Bizzare I tried so many things - except apparently from the most straight forward way.

But thanks for pointing out the obvious to me

Um, yeah - I see, it is defined here:

await mainCurrencyConversion(mainCur, mainCurMatchField)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.