Help

Re: Multiple fields in script config

Solved
Jump to Solution
2498 1
cancel
Showing results for 
Search instead for 
Did you mean: 
yiddy
4 - Data Explorer
4 - Data Explorer

I am new to scripting & know that I dont know exactly what I am doing however I like to learn & am kind of learning on the job taking it 1 step at a time.

When creating a script the following code will allow the user to choose which table & field they want to use in the script from the script settings.

 

// Click the "gear" icon in the top right to view settings
let config = input.config({
    title: "Script Title",
    description: "Script Description",
    items: [
        input.config.table('selectedTable', {
            label: 'Table to use',
            description: 'Pick any table in this base!'
        }),
        input.config.field('selectedField', {
            label: 'Field inside the above table',
            parentTable: 'selectedTable',
        })
    ]
});

 

I want to be able to select multiple fields. But I only want to be able to select:

  • Fields that are either a singleLineText or a multilineText.
  • Only be able to select each field once.

How would I do that?

1 Solution

Accepted Solutions
Alexey_Gusev
13 - Mars
13 - Mars

Here the piece of code in my program doing exactly what your want, 

 

let tfields=tableOne.fields.map(f=>f.name.toString())
let ask=''; let chosen=[]; tfields.unshift('DONE!');
while (ask!='DONE!') {
ask=tfields.length==1? 'DONE!':await input.buttonsAsync('Choose fields: ', tfields)
chosen.push(tfields.splice(tfields.indexOf(ask),1)[0]);
output.clear; output.text('Chosen fields: '+chosen.join(', '));
output.text('==================')
}
chosen.pop();

 

except that you need to adjust first line - change table name and add field type filtering, like

 

.fields.filter(fl=>fl.type.includes('Text')).map(

 

after that piece, when user select DONE, array 'chosen' contains selected field names

See Solution in Thread

4 Replies 4

> Fields that are either a singleLineText or a multilineText.
Hm, I don't know of a way to restrict users to picking from specific field types, so you'd have to do a check when they were actually running the app, and then prevent them from using it if you detected the wrong type of field was selected

I've put something together below that allows for multiple fields and checks whether one of the selected fields is a `singleLineText` type for you to start with

re: only being able to select each field once
If I were you I'd compile all the selected field IDs and check whether there were duplicates I think

 

let settings = input.config({
 title: `Test`,
 description: `Test`,
 items: [
 input.config.table("table", { label: `Table` }),
 input.config.field("field", { parentTable: `table`, label: `Field` }),
 input.config.field("field2", { parentTable: `table`, label: `Field 2` }),
],
});

let { table, field } = settings;

test()

function test(){
if (field.type != "singleLineText"){
 console.log("Field must be single line text")
}
else{
 console.log("OK")
}

}

 

Thank you @TheTimeSavingCo. What I'm looking for is something that would actually depend on how many fields there are in the base. So if the table has 20 fields, it should allow to choose all of those fields, however it should work dynamically without knowing how many fields are in the table when writing the script.

Alexey_Gusev
13 - Mars
13 - Mars

Here the piece of code in my program doing exactly what your want, 

 

let tfields=tableOne.fields.map(f=>f.name.toString())
let ask=''; let chosen=[]; tfields.unshift('DONE!');
while (ask!='DONE!') {
ask=tfields.length==1? 'DONE!':await input.buttonsAsync('Choose fields: ', tfields)
chosen.push(tfields.splice(tfields.indexOf(ask),1)[0]);
output.clear; output.text('Chosen fields: '+chosen.join(', '));
output.text('==================')
}
chosen.pop();

 

except that you need to adjust first line - change table name and add field type filtering, like

 

.fields.filter(fl=>fl.type.includes('Text')).map(

 

after that piece, when user select DONE, array 'chosen' contains selected field names

This is perfect. Thank you!!!