Highlighted

AcroForm mySaveAs throwing an error : UnsupportedValueError: Value is unsupported

Community Beginner ,
Aug 29, 2020

Copy link to clipboard

Copied

I'm new to javascript. I've browsed the forum and tried every solution that I've come across here and yet still stuck with the mySaveAs function giving me the same error no matter what my button script is in my AcroForm.  I'm not able to figure out how to resolve this error. Appreciate all the help and assistance. Thanks in advance.

ERROR:

UnsupportedValueError: Value is unsupported. ===> Parameter cPath.
Doc.saveAs:7:Field Save:Mouse Up

 

Below are my Scripts.

Folder level script:

var mySaveAs = app.trustedFunction(

function(doc,path) {

app.beginPriv();

doc.saveAs(path);

app.endPriv();

}
);

myTrustedSpecialTaskFunc = app.trustedFunction(

function(doc,path) {

app.beginPriv();

try {

mySaveAs(doc,path);

} catch (e) {

app.alert("Error During Save - " + e);

}

app.endPriv();

}
);


Mouse-up Button script:
//
// Before saving the data, make sure that all required
// fields are valid
//
function myDateSTring(){
return util.printd("mm/dd/yyyy h:MMtt", new Date());
}
if(FormValidFields())
{

var directory = "/C/Users/aUsers/Folder/Subfolder/";

var SignedOffBy = this.getField('SignedOffBy');
if (this.getField("SignedOffBy").value == "SignedOffBy.valueAsString"){
SignedOffBy = SignedOffBy.valueAsString;
}
var myFileName = SignedOffBy + " - " + myDateSTring() + ".pdf";
var mySaveAs = directory + myFileName;
if (typeof(mySaveAs) == "function") {
mySaveAs(this, directory, SignedOffBy +"-"+ myDateSTring()+".pdf");
app.alert("This Form " + SignedOffBy +"-"+ myDateSTring()+ " has saved successfully to the following location: /C/Users/aUsers/folder/subfolder/" , 3);
} else {
app.alert("Missing Save Function. Please contact forms administrator ");
}

}

Topics

How to

Views

70

Likes

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

AcroForm mySaveAs throwing an error : UnsupportedValueError: Value is unsupported

Community Beginner ,
Aug 29, 2020

Copy link to clipboard

Copied

I'm new to javascript. I've browsed the forum and tried every solution that I've come across here and yet still stuck with the mySaveAs function giving me the same error no matter what my button script is in my AcroForm.  I'm not able to figure out how to resolve this error. Appreciate all the help and assistance. Thanks in advance.

ERROR:

UnsupportedValueError: Value is unsupported. ===> Parameter cPath.
Doc.saveAs:7:Field Save:Mouse Up

 

Below are my Scripts.

Folder level script:

var mySaveAs = app.trustedFunction(

function(doc,path) {

app.beginPriv();

doc.saveAs(path);

app.endPriv();

}
);

myTrustedSpecialTaskFunc = app.trustedFunction(

function(doc,path) {

app.beginPriv();

try {

mySaveAs(doc,path);

} catch (e) {

app.alert("Error During Save - " + e);

}

app.endPriv();

}
);


Mouse-up Button script:
//
// Before saving the data, make sure that all required
// fields are valid
//
function myDateSTring(){
return util.printd("mm/dd/yyyy h:MMtt", new Date());
}
if(FormValidFields())
{

var directory = "/C/Users/aUsers/Folder/Subfolder/";

var SignedOffBy = this.getField('SignedOffBy');
if (this.getField("SignedOffBy").value == "SignedOffBy.valueAsString"){
SignedOffBy = SignedOffBy.valueAsString;
}
var myFileName = SignedOffBy + " - " + myDateSTring() + ".pdf";
var mySaveAs = directory + myFileName;
if (typeof(mySaveAs) == "function") {
mySaveAs(this, directory, SignedOffBy +"-"+ myDateSTring()+".pdf");
app.alert("This Form " + SignedOffBy +"-"+ myDateSTring()+ " has saved successfully to the following location: /C/Users/aUsers/folder/subfolder/" , 3);
} else {
app.alert("Missing Save Function. Please contact forms administrator ");
}

}

Topics

How to

Views

71

Likes

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
Adobe Community Professional ,
Aug 29, 2020

Copy link to clipboard

Copied

Remove following line:

var mySaveAs = directory + myFileName;

This line makes no sense.

Likes

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
Reply
Loading...
Most Valuable Participant ,
Aug 30, 2020

Copy link to clipboard

Copied

A file name can't contain characters such as "/" or ":"...

Likes

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
Reply
Loading...
Most Valuable Participant ,
Aug 30, 2020

Copy link to clipboard

Copied

Also, this part of the code doesn't make much sense to me:

 

var SignedOffBy = this.getField('SignedOffBy');
if (this.getField("SignedOffBy").value == "SignedOffBy.valueAsString"){
SignedOffBy = SignedOffBy.valueAsString;
}

 

What are you trying to compare here, exactly? And you need to think about what would happen if the values you're comparing are not equal. You'll be using a Field object directly in the file-name you're trying to save under.

This is a good example of why it's not good to change the type of a variable in the middle of your code.
If you want to have one variable that points to a Field and one to the field's value, declare two different variables, don't "recycle" the first one.

Likes

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
Reply
Loading...
Community Beginner ,
Aug 31, 2020

Copy link to clipboard

Copied

Thank you so much Bernd Alheit & try67 for the input and pointing out the mistakes in my code.
As suggested, I removed the following lines from the Button script:
var mySaveAs = directory + myFileName;
&
var SignedOffBy = this.getField('SignedOffBy');
if (this.getField("SignedOffBy").value == "SignedOffBy.valueAsString"){
SignedOffBy = SignedOffBy.valueAsString;
}

That took care of the 'UnsupportedValueError'. But now I have a new issue with the code.
Though the code seems to be executing without any error and showing the correct file name in the '...saved successfully...' message, it's actually not saving the file. What else could I be doing wrong? Thanks again in advance.

More info about my form:

 

SignedOffBy - is a Dropdown field with a field script and a document level script as below:

Field script:
this.getField("SignedOffBy").valueAsString = SignedOffBy.valueAsString;
Document level script:
function SignedOffBy(){
getField("SignedOffBy").valueAsString = SignedOffBy.valueAsString;
}

 

mySaveAs - has a document level script as below:
function mySaveAs(){
// build new file name
var directory = "/C/Users/getdr/Dropbox/EDPChecklist/";
var SignedOffBy = this.getField('SignedOffBy').valueAsString;
var myNewFileName = SignedOffBy + " - " + myDateSTring() + ".pdf";
mySaveAs = "/C/Users/getdr/Dropbox/EDPChecklist/" + SignedOffBy + " - " + myDateSTring()+".pdf";
}

 

Mouse-up Button script:
//
// Before saving the data, make sure that all required
// fields are valid
//
function myDateSTring(){
return util.printd("mm/dd/yyyy h:MMtt", new Date());
}
if(FormValidFields()){
var directory = "/C/Users/aUsers/Folder/Subfolder/";
var SignedOffBy = this.getField('SignedOffBy').valueAsString;
var myFileName = SignedOffBy + " - " + myDateSTring() + ".pdf";

if (typeof(mySaveAs) == "function") {
mySaveAs(this, directory, SignedOffBy +"-"+ myDateSTring()+".pdf");
app.alert("This Form " + SignedOffBy +"-"+ myDateSTring()+ " has saved successfully to the following location: /C/Users/aUsers/folder/subfolder/" , 3);
} else {
app.alert("Missing Save Function. Please contact forms administrator ");
}
}

Likes

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
Reply
Loading...
Most Valuable Participant ,
Aug 31, 2020

Copy link to clipboard

Copied

There are multiple issues here. First of all, the fact you added an alert after the mySaveAs command that says it was successful does not mean that's actually the case.

Also, you're passing multiple parameters to this function, but there are none defined in the function definition. You need to decide which way to go with and stick with it.

And also, you didn't change the myDateSTring function to not include the characters I said can't be included in a file-name, so it can't work, no matter what.

Likes

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
Reply
Loading...
Adobe Community Professional ,
Aug 31, 2020

Copy link to clipboard

Copied

Your document level function mySaveAs doesn't save the document.

Likes

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
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF