Skip to main content
Solved

Multiple fields in script config


Forum|alt.badge.img+2
  • Participating Frequently
  • 7 replies

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?

Best answer by Alexey_Gusev

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

View original
Did this topic help you find an answer to your question?

4 replies

TheTimeSavingCo
Forum|alt.badge.img+28

> 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") } }

 


Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • 7 replies
  • January 26, 2023
TheTimeSavingCo wrote:

> 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
Forum|alt.badge.img+23
  • Brainy
  • 1120 replies
  • Answer
  • January 27, 2023

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


Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • 7 replies
  • January 27, 2023
Alexey_Gusev wrote:

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!!!


Reply