Help

Reading formula result as string

Topic Labels: Scripting extentions
Solved
Jump to Solution
2020 8
cancel
Showing results for 
Search instead for 
Did you mean: 
Scott_Mullin
6 - Interface Innovator
6 - Interface Innovator

Hello,

I believe this is simple, but I don’t understand what syntax is needed. I’m trying to read the results of a single-select field as a string. I’m doing a running total calculation, but resetting it whenever a certain reading is found. The running total part was working, but I can’t figure out how to get the single select output as a string.

When I run this, I get:
typeof respGroup.records[0] returns “Object”
output.text(typeof respGroup.records[0].getCellValueAsString) returns “Function”

let table = base.getTable(‘Prints’);
let view = table.getView(‘MTBF layout’);

let respGroup = await view.selectRecordsAsync({fields: [‘NDD - Responsible Group’]}); //NDD - Responsible Group must be manually filled out!
let elapsedTime = await view.selectRecordsAsync({fields: [‘NDD - Elapsed print time’]}); //NDD - Elapsed print time is a calculated field
let groupRecords = respGroup.records;

//trying to understand how to get the group records into a string format
output.text(typeof respGroup.records[0])
output.text(“and the record is”)
output.text(typeof respGroup.records[0].getCellValueAsString)

1 Solution

Accepted Solutions

Like I showed in my example, you have to actually tell the script which field. .getCellValueAsString("Name or ID of Field")

See Solution in Thread

8 Replies 8

Get any cell value as a string with the aptly named function record.getCellValueAsString("Name or ID of Field")

Thank you. I must be referencing the records incorrectly. Could you help me with that syntax? I ran a test and got this output for the first index:

output.text(typeOf respGroup.records[0].getCellValueAsString) returns “Function”

Like I showed in my example, you have to actually tell the script which field. .getCellValueAsString("Name or ID of Field")

Hmm ok so I was missing the name or id. When I add it, I get a string output, but no string value

output.text(respGroup.records[0].getCellValueAsString(‘NDD - Responsible Group’)) returns nothing

Does it return a string or does it return nothing? In scripting those are different.

Does the first record from the view you’re querying have a value for that field?

The first record does have a value for that field. I can output the table and it gives me all the record IDs and names.

When I use typeOf, it says the output is a string. However, when I use the output.text() function there’s nothing printed in the console. I’m not clear on whether the output is an empty string or something else

The first record in the grid view is not necessarily the first record returned in the results.

Try console.log() instead of output.text() and post a screen shot of the result. Also include a screen shot of the actual record data from the grid view.

Ah that was it! I can read a different index and get a value out. Thank you both! I really appreciate it!

Have a good weekend