Get list of PDF-files from folder to populate drop-down

Post Reply
User avatar
JimmyHartington
Advanced member
Posts: 279
Joined: Tue Mar 22, 2011 7:38 am

Get list of PDF-files from folder to populate drop-down

Post by JimmyHartington »

Hi

I am creating a flow, where I start with a Submit Point.

And I would like to have the user fill out metadata.
One of them should be a dropdown of files from a folder on the Switch-Server.
The contents of the folder will only be pdfs but it the number of pdfs changes over time.

I tried to set the Data values of the dropdown to a script expresision (see code below), but SwitchClient just shows me a text-entry field. If I set values manually, then I get a dropdown.

Image

I hope somebody can help.

Code: Select all

var theDir = new Dir("D:\SB-S\kursussystem-v2\APPROVED");

var theEntries = theDir.entryList("*.pdf", Dir.Files, Dir.Name);

	var list = new Array;

	for (var i = 0; i < theEntries.length; i++) 

		list.push(theEntries[i]);

	list;
loicaigon
Advanced member
Posts: 361
Joined: Wed Jul 10, 2013 10:22 am

Re: Get list of PDF-files from folder to populate drop-down

Post by loicaigon »

Hi,
Not helping but your code just works fine onto my mac :S
User avatar
Terkelsen
Advanced member
Posts: 297
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Re: Get list of PDF-files from folder to populate drop-down

Post by Terkelsen »

Hi Jimmy ;)
Try This:

var theDir = new Dir("D:\\SB-S\kursussystem-v2\APPROVED");

var theEntries = theDir.entryList("*.pdf", Dir.Files, Dir.Name);

var list = new Array;

for (var i = 0; i < theEntries.length; i++)

list.push(theEntries);

list;


The extra backlash made all the difference for me.
User avatar
JimmyHartington
Advanced member
Posts: 279
Joined: Tue Mar 22, 2011 7:38 am

Re: Get list of PDF-files from folder to populate drop-down

Post by JimmyHartington »

Terkelsen wrote:The extra backlash made all the difference for me.
Thanks to Erik to point me in the right direction.
I needed to use doublebackslash in the complete path. And then it worked.

I have added some extra-code to remove the extension of the filename.

Finished and working code:

Code: Select all

var theDir = new Dir("D:\\SB-S\\kursussystem-v2\\APPROVED");
var theEntries = theDir.entryList("*.pdf", Dir.Files, Dir.Name);
var list = new Array;
for (var i = 0; i < theEntries.length; i++)
  list.push(theEntries[i].substring(0, theEntries[i].lastIndexOf('.')));
 
list;
NEOSA
Member
Posts: 39
Joined: Thu Mar 10, 2016 6:31 pm

Re: Get list of PDF-files from folder to populate drop-down

Post by NEOSA »

Hi All,

I tried a such Expression in a Submit Point (Switch 2018U3), but I obtain a list which is not a DropDown List :

Image

It should be shown as a list :

Code: Select all

12000_BASIQUE_PAYSAGE_520X720
12000_BASIQUE_SFP_520X720
12000_CAHIER_DEPLIANT_520X720
12000_CAHIER_MARKS_520X720
12000_CAHIER_MARKS_Avec_Couv_520X720
12000_CAHIER_SIMPLE_520X720
12000_DCC_COUVERTURE_520X720
12000_DCC_INTERIEUR_520X720
12000_PPG_PPG_520X720
Any ideas how to modify the expression ? Adding like a CR/BR ?

Thanks for replies.
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Get list of PDF-files from folder to populate drop-down

Post by Padawan »

I suspect that the datatype of your metadata property is text instead of dropdown. Can you check this?
NEOSA
Member
Posts: 39
Joined: Thu Mar 10, 2016 6:31 pm

Re: Get list of PDF-files from folder to populate drop-down

Post by NEOSA »

Padawan wrote: Thu Apr 04, 2019 5:05 pm I suspect that the datatype of your metadata property is text instead of dropdown. Can you check this?
It is a DropDown List :

Image
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Get list of PDF-files from folder to populate drop-down

Post by Padawan »

Strange. Afaik I always return arrays for drop downs, I'll check again tomorrow.
NEOSA
Member
Posts: 39
Joined: Thu Mar 10, 2016 6:31 pm

Re: Get list of PDF-files from folder to populate drop-down

Post by NEOSA »

Padawan wrote: Thu Apr 04, 2019 7:36 pm Strange. Afaik I always return arrays for drop downs, I'll check again tomorrow.
Apparently, there was an issue with my flow : I deleted the Tool, re-create & it works now :-)

Thank you Padawan to take care ;-)

Image
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Get list of PDF-files from folder to populate drop-down

Post by Padawan »

You're welcome :)
Post Reply