Help

Re: Possible to pass a string into a function

Solved
Jump to Solution
567 0
cancel
Showing results for 
Search instead for 
Did you mean: 

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?

1 Solution

Accepted Solutions
JonathanBowen
13 - Mars
13 - Mars

Hi @Kim_Trager1 - 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:

Screenshot 2020-06-26 at 20.55.55

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.

See Solution in Thread

4 Replies 4

I don’t see where matchField has been defined.

JonathanBowen
13 - Mars
13 - Mars

Hi @Kim_Trager1 - 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:

Screenshot 2020-06-26 at 20.55.55

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.

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)