Skip to main content
Solved

Help with Script

  • August 8, 2020
  • 3 replies
  • 28 views

Michael_Andrew
Forum|alt.badge.img+22

I am trying to add all records from a view in a separate table to a field for all records in a view on another table.

let TBTable = base.getTable(‘Technical Comments for VB’);
let TBView = TBTable.getView(“Shared to All Trigger”)
let TBQuery = await TBView.selectRecordsAsync();
let TBRecord = TBQuery.records;
let VBTable = base.getTable(‘Verifier / Trainer Body’);
let VBView = VBTable.getView(“Verifier Bodies (Public List)”)
let VBQuery = await VBView.selectRecordsAsync();
let VBRecords = VBQuery.records;
let d =
VBRecords.forEach(c => d.push({id: c.id}));
await TBTable.updateRecordAsync(TBRecord.id,{‘Verifier Body’: d});
output.markdown(’# Done :rocket: ’)

I am getting an error that the record is not defined. Can someone help?

Thanks,

Best answer by Kamille_Parks11

Thanks. Sorry where does that part go in the script. I apologize I’m very new to coding.


its a replacement for your current line with updateRecordAsync.

3 replies

Kamille_Parks11
Forum|alt.badge.img+27

Your problem is you’ve passed TBRecord.id, but TBRecord does not have a property of id. As you’ve defined it, TBRecord is an array of records which looks something like this:

[
    {id: xxx1, name: "Record 1"},
    {id: xxx2, name: "Record 2"},
    {id: xxx3, name: "Record 3"}
    ...
]

You’ll need to loop through each item in that array, similar to how you’ve done with VBRecords, like this:

TBRecord.forEach(x => {
    TBTable.updateRecordAsync(x.id, {'Verifier Body': d})
})

Michael_Andrew
Forum|alt.badge.img+22
  • Author
  • Brainy
  • 53 replies
  • August 8, 2020

Your problem is you’ve passed TBRecord.id, but TBRecord does not have a property of id. As you’ve defined it, TBRecord is an array of records which looks something like this:

[
    {id: xxx1, name: "Record 1"},
    {id: xxx2, name: "Record 2"},
    {id: xxx3, name: "Record 3"}
    ...
]

You’ll need to loop through each item in that array, similar to how you’ve done with VBRecords, like this:

TBRecord.forEach(x => {
    TBTable.updateRecordAsync(x.id, {'Verifier Body': d})
})

Thanks. Sorry where does that part go in the script. I apologize I’m very new to coding.


Kamille_Parks11
Forum|alt.badge.img+27
  • Brainy
  • 2679 replies
  • Answer
  • August 8, 2020

Thanks. Sorry where does that part go in the script. I apologize I’m very new to coding.


its a replacement for your current line with updateRecordAsync.