Skip to main content
Solved

Reading formula result as string

  • September 2, 2022
  • 8 replies
  • 11 views

Forum|alt.badge.img+10

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)

Best answer by Kamille_Parks11

Scott_Mullin wrote:

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")

View original
Did this topic help you find an answer to your question?

8 replies

Kamille_Parks11
Forum|alt.badge.img+25

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


Forum|alt.badge.img+10
  • Author
  • Inspiring
  • 15 replies
  • September 2, 2022
Kamille_Parks11 wrote:

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”


Kamille_Parks11
Forum|alt.badge.img+25
Scott_Mullin wrote:

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")


Forum|alt.badge.img+10
  • Author
  • Inspiring
  • 15 replies
  • September 2, 2022
Scott_Mullin wrote:

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”


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


Kamille_Parks11
Forum|alt.badge.img+25
Scott_Mullin wrote:

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?


Forum|alt.badge.img+10
  • Author
  • Inspiring
  • 15 replies
  • September 2, 2022
Kamille_Parks11 wrote:

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


kuovonne
Forum|alt.badge.img+27
  • Brainy
  • 6001 replies
  • September 2, 2022
Scott_Mullin wrote:

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.


Forum|alt.badge.img+10
  • Author
  • Inspiring
  • 15 replies
  • September 2, 2022
kuovonne wrote:

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


Reply