Skip to main content
Solved

Possible to pass a string into a function


Kim_Trager1
Forum|alt.badge.img+23

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?

Best answer by JonathanBowen

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:

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.

View original
This topic has been closed for replies.

4 replies

Bill_French
Forum|alt.badge.img+19

I don’t see where matchField has been defined.


JonathanBowen
Forum|alt.badge.img+18

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:

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.


Kim_Trager1
Forum|alt.badge.img+23

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:

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


Bill_French
Forum|alt.badge.img+19

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

await mainCurrencyConversion(mainCur, mainCurMatchField)