• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

wrote a script to check certain fields and they all work, but the SAVE does not work

Community Beginner ,
Aug 28, 2024 Aug 28, 2024

Copy link to clipboard

Copied

Wrote up a quick script to check certain fields for when people fill out a form that would be either e-mailed to them or downloaded from a web page.   I would like the file to be saved to their desktop so that they could later e-mail it to the appropriate people. All the fields are checked without a problem, just the save doesn't work 😞

 

Here is my script:

 

var error=false;

var message="You must enter a value for the following required fields:\r\n";

var b1=this.getField("Name");
var b2=this.getField("Address");
var b3=this.getField("City");
var b4=this.getField("Zip");
var b5=this.getField("E-Mail");
var b6=this.getField("Signature1");
var b7=this.getField("Signature2");
var b8=this.getField("Signature3");

if(b1==undefined || b1.value.length<1)

{

error=true;

message+="You must fill out Name before saving\r\n"

}

if(b2==undefined || b2.value.length<1)

{

error=true;

message+="You must fill out Address before saving\r\n"

}

if(b3==undefined || b3.value.length<1)
{

error=true;

message+="You must fill out City before saving\r\n"

}

if(b4==undefined || b4.value.length<1)

{

error=true;

message+="You must fill out Zip before saving\r\n"

}
if(b5==undefined || b5.value.length<1)

{

error=true;

message+="You must fill out E-Mail before saving\r\n"

}

if(b6==undefined || b6.value.length<1)
{

error=true;

message+="You must fill out SCAF COE Signature before saving\r\n"

}

if(b7==undefined || b7.value.length<1)

{

error=true;

message+="You must fill out CIF-SS Signature before saving\r\n"

}

if(b8==undefined || b8.value.length<1)


{

error=true;

message+="You must fill out CIF-LA Signature before saving\r\n"

}

if(!error)

{

this.save();

}

else

{

app.alert(message,3);

}

 

TOPICS
Create PDFs , How to , PDF , PDF forms

Views

183

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 29, 2024 Aug 29, 2024

You have to know the exact path, which would be different on every computer.  You can save it to it's current location (Desktop, Documents, anywhere else), like this:

this.saveAs(this.path);

However, you would have to run that script from the console or create a trusted function in a folder level script and call that function from your form like this:

 

My_save_function = app.trustedFunction( function (oDoc)
{
app.beginPriv();
oDoc.saveAs(oDoc.path);
app.endPriv();
})

 

Then call the function from you

...

Votes

Translate

Translate
Community Expert ,
Aug 28, 2024 Aug 28, 2024

Copy link to clipboard

Copied

this.save() is not a function.  Saving silently is privileged, meaning it can only be executed from the console, a trusted function in a folder level script, or an Action.  You can use Save As with this script:  app.execMenuItem("SaveAs");  Here's an article on saving documents with scripts.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2024 Aug 28, 2024

Copy link to clipboard

Copied

i'm still trying to learn all of that, how would you code the script to save the file to the desktop or to the documents file on any computer??  thanks for your help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2024 Aug 29, 2024

Copy link to clipboard

Copied

You have to know the exact path, which would be different on every computer.  You can save it to it's current location (Desktop, Documents, anywhere else), like this:

this.saveAs(this.path);

However, you would have to run that script from the console or create a trusted function in a folder level script and call that function from your form like this:

 

My_save_function = app.trustedFunction( function (oDoc)
{
app.beginPriv();
oDoc.saveAs(oDoc.path);
app.endPriv();
})

 

Then call the function from your form like this:

My_save_function(this);

The line above replaces this.save() in your script.  However, this would not be suitable for widely distributed form because all recipients would need the JavaScript file with the trusted function installed on their computers.  It's probably best to stick with app.execMenuItem("SaveAs");  When there are no errors you could ask them to save the file to their hard drive with a popup and then trigger the SaveAs menu item like this:

if(!error)

{app.alert("Please save the file.", 1); app.execMenuItem("SaveAs");}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 29, 2024 Aug 29, 2024

Copy link to clipboard

Copied

LATEST

Thank you!!!!!!!!!!   that is a fantastic solution and it will work across different computers, more of a universal fix.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines