Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adding new javascript in LiveCycle script editor

Avatar

Level 4

The form has a Print button and already has this javascript xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 1, 0, 0, 0);

How do I add the following javascript to the same button and its click event?

newDocName = "";
f1 = this.getField("topmostSubform[0].Page1[0].Last_Name[0]").valueAsString;
if (f1!="") newDocName += f1 + " ";
f2 = this.getField("topmostSubform[0].Page1[0].First_Name[0]").valueAsString;
if (f2!="") newDocName += f2 + " ";
f3 = this.getField("topmostSubform[0].Page1[0].Date[0]").valueAsString;
if (f3!="") newDocName += f3 + " ";
f4 = this.getField("topmostSubform[0].Page1[0].Email[0]").valueAsString;
if (f4!="") newDocName += f4;

newDocName = newDocName.replace(/[\\,\/,\:,\*,\?,\",\<,\>,\|,\,,\n,\r]/g,"");

docPath = this.path+"";
docPath = docPath.substring(0, docPath.lastIndexOf("/")+1);

mySaveAs(this,docPath+newDocName+".pdf");

I had this working in Acrobat on an earlier version of the same form (with an external script also in the Acrobat directory -- so it all worked perfectly as a trusted function), but on this form, I don't have full access. My only option is to try to add this javascript to save the file with a new filename by using LiveCycle.

0 Replies

Avatar

Level 4

I used the MouseUp event in LC Script Editor and pasted in the code. The page prints, but it doesn't save with the new file name. It doesn't save at all. So I'm assuming that this javascript, which works in Acrobat in Button Properties>Run a Javascript, won't work in LC. The script will have to be modified, at the very least, and may not work as intended. Any perspectives on this are welcome.

Avatar

Level 4

Here is the trusted function file in Acrobat?javascript

var mySaveAs = app.trustedFunction(
function(doc,name){
app.beginPriv();
doc.saveAs(name);
app.endPriv();
})

How can I adapt the code below (which works in Acrobat) for LC?

newDocName = "";
f1 = this.getField("topmostSubform[0].Page1[0].Last_Name[0]").valueAsString;
if (f1!="") newDocName += f1 + " ";
f2 = this.getField("topmostSubform[0].Page1[0].First_Name[0]").valueAsString;
if (f2!="") newDocName += f2 + " ";
f3 = this.getField("topmostSubform[0].Page1[0].Date[0]").valueAsString;
if (f3!="") newDocName += f3 + " ";
f4 = this.getField("topmostSubform[0].Page1[0].Email[0]").valueAsString;
if (f4!="") newDocName += f4;

newDocName = newDocName.replace(/[\\,\/,\:,\*,\?,\",\<,\>,\|,\,,\n,\r]/g,"");

docPath = this.path+"";
docPath = docPath.substring(0, docPath.lastIndexOf("/")+1);

mySaveAs(this,docPath+newDocName+".pdf");