Skip to main content
Participant
August 29, 2020
Question

AcroForm mySaveAs throwing an error : UnsupportedValueError: Value is unsupported

  • August 29, 2020
  • 2 replies
  • 1179 views

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 ");
}

}

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
August 30, 2020

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

try67
Community Expert
Community Expert
August 30, 2020

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.

smaz207Author
Participant
August 31, 2020

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 ");
}
}

Bernd Alheit
Community Expert
Community Expert
August 30, 2020

Remove following line:

var mySaveAs = directory + myFileName;

This line makes no sense.