Help

.find or .filter cannot find any value in Script

Topic Labels: Automations Data Extensions
413 1
cancel
Showing results for 
Search instead for 
Did you mean: 
moony
4 - Data Explorer
4 - Data Explorer

I am trying to find and compare exact value from a table to other.

Table A: I will insert 'Key' of other table's record. Once I insert the key, automation script will run and it will search the corresponding record.

Table B: Bunch of records are exist in this table with unique "Key". 

 

I am trying to make script as below:

 

 

 

console.log("스크립트를 실행합니다.")
let tableName = "Review Ticket"
let tabledata = base.getTable(tableName);

let record_id = input.config().recordID

let record2 = await tabledata.selectRecordAsync(
  record_id, {fields: ["Title", "Key", "Task to Review", "Subtask to Review", "Asset to Review"]}
  )
let input_key = record2.getCellValueAsString("Key").toUpperCase()

if (input_key.charAt(0) == "T") {
var table = base.getTable("Tasks")
// var fieldName = "Title"
// var keyValue = "Key"
var queryResult = await table.selectRecordsAsync({fields: [fieldName, keyValue]})

var findKey = queryResult.records.filter(element => (
  element.getCellValueAsString(keyValue) == input_key))
console.log(findKey)

console.log(queryResult.records[0].getCellValueAsString(keyValue))

await tabledata.updateRecordAsync(record2, { 
    'Task to Review': findKey,
    });
  

  console.log(input_key + " Task를 추가했습니다.")
}

 

 

 

console.log(findKey) always return '[ ]'.(returns 'undefined' in case of I use .find)

but log below returns proper value.

 

 

console.log(queryResult.records[0].getCellValueAsString(keyValue))

 

 

 

Please help me to solve it.

1 Reply 1

Hi,
on a quick view, you uppercased Key but nothing known about the case of second table values .
Also, in var queryResult you commented variables, which then trying to use. But I suppose it's not a reason of problem, as it should cause another type of error.