Help

Re: Loop through records in a view and return value of lookup field

Solved
Jump to Solution
1037 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Claire_Conza
6 - Interface Innovator
6 - Interface Innovator

Hi all

Hope you can help.

Using the scripting block, how could I loop through the records and return the value of a lookup field. All other fields are fine but linked and lookup fields throw an error.

Here’s my code…

let table = base.getTable("Daily Orders");
let view = table.getView("Unfulfilled Daily Orders");
let sku = table.getField("Line Items: Sku"); //Lookup Field



let result = await view.selectRecordsAsync({
sorts: [{field: "Line Items: Variant Id", direction: "asc"}]
});

for (let record1 of result.records) {
  output.text(record1.getCellValue(sku)); // throws an error
 } 

ERROR

Error: Unknown value ‘AlexSaleBeanieAdultCharcoal’ passed to output.text()

at main on line 12

image

Please help!

Thanks

Claire

1 Solution

Accepted Solutions
Justin_Barrett
18 - Pluto
18 - Pluto

Lookup fields return arrays, even if they’re only looking up from a single linked record. Instead of output.text, use output.inspect. This will display the literal item you’re receiving, even if it’s an array.

See Solution in Thread

1 Reply 1
Justin_Barrett
18 - Pluto
18 - Pluto

Lookup fields return arrays, even if they’re only looking up from a single linked record. Instead of output.text, use output.inspect. This will display the literal item you’re receiving, even if it’s an array.