Skip to main content
Solved

Possible to pass a string into a function

  • June 26, 2020
  • 4 replies
  • 57 views

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.

This topic has been closed for replies.

4 replies

Forum|alt.badge.img+19
  • Inspiring
  • June 26, 2020

I don’t see where matchField has been defined.


JonathanBowen
Forum|alt.badge.img+18
  • Inspiring
  • Answer
  • June 26, 2020

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
  • Author
  • Brainy
  • June 28, 2020

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


Forum|alt.badge.img+19
  • Inspiring
  • June 28, 2020

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

await mainCurrencyConversion(mainCur, mainCurMatchField)