Good morning. I have a question, which I could not solve by checking the docs:
In a table, I have stations that are present and the usecases, each station works on.
In a second table, I do the employer processing and want to assign, which stations an employer has to contact, based on usecase.
But. I dont want to do it manually. I want to have a script, that sets the linked values, based on selected use case.
So, If I select “Entry”, like int he screenshot, I want an automation rule to fire a script, that gets me all stations that contain the use case “Entry” and then sets the links accordingly in the “ToBeDone” column.
Part one of the problem was simple and gives the desired results:
await bse.query('select Station from Stationen where UseCase has any of ("Entry")');
Ok, I got it working. For those, who are interested:
Do not trust the documentation on the website, it is not up to date! I got plenty of “xxx is not a function” errors, for example for base.getColumns(“tablename”), which is obviously not there:
See base dump from console here:
Dump base, table and other objects you intend to use in JS to console to see the currently implemented functions.
Without that, you will tear your hair out.
Now, for the sollution:
//console.log(base);
const bse = base; // I just wanted to go with another name here ;-)
var usecase = await bse.query('select _id from Stationen where UseCase has any of ("Entry")');
//console.log(usecase);
const tble_lfzttl = bse.getTableByName('Processing');
//console.log(tble_lfzttl);
//const columns = await bse.listColumns('Processing'); // return table's columns, check on console to retrieve link id
const linkId = "xxxx";
usecase.forEach(function(einArrayElement) {
// console.log(einArrayElement['_id']);
bse.addLink(linkId, "Processing", "Stationen", bse.context.currentRow['_id'], einArrayElement['_id']);