Skip to main content
Participating Frequently
October 6, 2017
Answered

Save PDF to File Path based on Form Field selection

  • October 6, 2017
  • 3 replies
  • 1306 views

Hello!

I am trying to create a form that saves to a specific path depending on the option you select for a drop-down field. So, for instance, you have a drop down field and you select 1,2,3,4 and each selection will change where the file is saved. Is this possible?

I've successfully made a document that saves to one location using folder-level scripts but I am not sure how to add an if-else statement so the file location is appended depending on what value is entered in a specific field.

// determine the directory path for the current document

var directory = "/shared$/Manuals & Documentation/MCR/"

if (typeof(mySaveAs) == "function") {

  mySaveAs(this, directory, "MCR-" + this.getField("mcr #").value + " (" + this.getField("model #").value + ")" + ".pdf");

  app.alert("Document archived successfully");

} else {

  app.alert("Save script missing or installed incorrectly. Please save-as manually or contact STR");

}

Thank you so much for all the help!!!!

This topic has been closed for replies.
Correct answer Bernd Alheit

var directory = this.getField("dropdown field").value;

Set the export values of the dropdown to the different directories.

3 replies

Bernd Alheit
Community Expert
Community Expert
October 6, 2017

You can set directory to the value of the dropdown.

Participating Frequently
October 6, 2017

Ahh I can? do you know how I would write that? Thank you!

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
October 6, 2017

var directory = this.getField("dropdown field").value;

Set the export values of the dropdown to the different directories.

Bernd Alheit
Community Expert
Community Expert
October 6, 2017

Your code uses the values of the fields "mcr #" and "model #". What miss you?

Karl Heinz  Kremer
Community Expert
Community Expert
October 6, 2017

You seem to be on the right track with saving the file to a custom path, based on two different fields. I am not quite sure about what you mean by using an if/else statement. You are already using one. Can you please be more specific about what your requirements are.

Participating Frequently
October 6, 2017

Thanks for the quick response, I am trying to add a way to switch the directory of the save depending on the field values. So the file will save to a different subfolder if I enter a different value in a field.

Karl Heinz  Kremer
Community Expert
Community Expert
October 6, 2017

You can do something like this:

var myValue = this.getField("MyField").value;

var theDirectory = "/some/default/directory/value/";

if (myValue == "value 1") {

  theDirectory = "/some/other/directory";

}

else if (myValue == "value 2") {

  theDirectory = "/and/a/third/directory/";

}

// ...

You don't need a plain "else" case here because if none of the if/if else tests get triggered, the default value that you set will be used for your directory.