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);
}
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
...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.
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!
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");}
Copy link to clipboard
Copied
Thank you!!!!!!!!!! that is a fantastic solution and it will work across different computers, more of a universal fix.