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;

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

Posted: Thu Apr 04, 2019 4:45 pm
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.

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

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

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

Posted: Thu Apr 04, 2019 5:12 pm
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

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

Posted: Thu Apr 04, 2019 7:36 pm
by Padawan
Strange. Afaik I always return arrays for drop downs, I'll check again tomorrow.

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

Posted: Thu Apr 04, 2019 7:47 pm
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

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

Posted: Fri Apr 05, 2019 8:42 am
by Padawan
You're welcome :)