Page 1 of 1

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

Posted: Mon Mar 07, 2016 10:35 am
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;

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

Posted: Mon Mar 07, 2016 2:02 pm
by loicaigon
Hi,
Not helping but your code just works fine onto my mac :S

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

Posted: Mon Mar 07, 2016 2:53 pm
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.

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

Posted: Tue Mar 08, 2016 11:09 am
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;