Help

Change table view via script

Topic Labels: Automations
911 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Merserwis_Spolk
4 - Data Explorer
4 - Data Explorer

Hi, I have a problem with my code. I have tried to limit linked records to specific view, but the view must change based on the chosen record from the previous column. My problem is how to change column->options.viewIdForRecordSelection?
Here is my code:

let table = base.getTable("_Zlecenia");
let field = table.getField(“Technik”);
let result = await table.selectRecordsAsync();
let value = input.config().Nazwa_Projektu;
console.log(table.fields[7].options.viewIdForRecordSelection);//this is the field that I want to influence on?
let _tableT = base.getTable("_Technicy");
let view = _tableT.views;
let num = 0;
let valueId = ‘’;
let replacements = ;
for(var i=0;i<view.length;i++)
{
if(view[i].name == value[0])
{
valueId = view[i].id; //take the id of view I want to change on
num = i;
replacements.push({num,before:table.getField(“Technik”).options.viewIdForRecordSelection,after:valueId }) //probably irrelevant
}
}

await table.updateRecordsAsync(table.fields[7].options.viewIdForRecordSelection,replacements); //How to put the new value here?

1 Reply 1

Several things:

  • When pasting code into the forums, please add three backticks ( ` ) on the line before and after your code so it renders properly. That makes it easier for us to read.
  • updateRecordsAsync() does exactly what the name implies: it updates records, or specifically, a set of record’s values for one or more Fields. It cannot update the configuration options for a Field.
  • Scripts can’t update Field, Table, or View configuration options, but a Custom App can.