These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Finalize form and save

StevenDL
Registered: Jun 4 2010
Posts: 15

I'm trying to make a button lock field, speel check, then prompt to save file. Everything work except the SaveAs part. I tried using a break statement in the for loop and that fixed the SaveAs, but it only hid the first set of buttons. What am i doing wrong??

var response1  = xfa.host.messageBox("No furthur can be made after finalizing this document. Are you sure you want to finalize? Click OK to continue.","WARNING: Finalizing Document!",2,1);
//xfa.host.messageBox( "response is " + response1); //get response code
if (response1 == 1)
{
	app.execMenuItem("Spelling:Check Spelling");
	var lock = xfa.resolveNode("form1.Page1._lockForm");        
// Get the field containers from each page.
	for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {
	    var oFields = xfa.layout.pageContent(nPageCount, "field");
	    var nNodesLength = oFields.length;
    // Set the field property.
 	   for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
	        oFields.item(nNodeCount).access = "protected";
 	   }
	}   
	form1.Page1.Subform1._lockForm.rawValue = 1;
	form1.Page1.Subform1.lockbtn.presence = "hidden";
	form1.Page1.Subform1.office.presence = "hidden";
	form1.Page1.P4.Add.presence = "hidden";
	form1.Page1.P4.Remove.presence = "hidden";
	form1.Page1.P7.Add.presence = "hidden";
	form1.Page1.P7.Remove.presence = "hidden";
	form1.Page1.P9.Add.presence = "hidden";
	form1.Page1.P9.Remove.presence = "hidden";
	form1.Page1.P2.Add.presence = "hidden";
	form1.Page1.P2.Remove.presence = "hidden";
	datefld.border.edge.color.value = "255,255,255";
	sector.border.edge.color.value = "255,255,255";
	mw.border.edge.color.value = "255,255,255";
	for (var i = 0; i < 21; i++)
		{
		var sSOM1 = "form1.Page1.Subform2a.Subform2b[" + i + "]";
		var oSubform1 = xfa.resolveNode(sSOM1);
		oSubform1.Add2.presence = "hidden";
		oSubform1.Remove2.presence = "hidden";
		break;
		}
 
	app.execMenuItem("SaveAs");
}
else
	note.rawValue = "noup";

StevenDL
Registered: Jun 4 2010
Posts: 15
I also tried putting all code in mouseup event and putting the saveas in click event; that fixed it in arcrobat 9.3.2, but it still didn't work in 8.2.2 (also didn't throw any errors in debugger).
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Have you opened the Acrobat JavaScript debugging console to see if you have any errors?

JavaScript is an interpretive language so basically each line of the code is read and run each time a script runs and stops dead when an error occurs.

You could also add some additional code to print a message to the JS console as each line or a group of lines runs and possibly locate the location at which the script quits.

George Kaiser

StevenDL
Registered: Jun 4 2010
Posts: 15
If I leave out the "break;" everything runs as it should except the save and I get the error below in the debugger.

oSubform1 has no properties
34:XFA:form1[0]:Page1[0]:Subform1[0]:lockbtn[0]:mouseUp

What code can I add to increase debugging level?

Sorry, I'm new at this.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Trying to perform a silent or automated save has some security restrictions. Why not let the user save the form?

If you want to do this, you may need to write an application folder level save function, and install this code on each client system using this form. Have you read Acrobat JS API Reference about 'execMenuItem()' method? [url=http://www.acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript]How to save a PDF with Acrobat JavaScript[/url] by Thom Parker


"break" does exactly what it says. It break out of any conditional block of code or script when this line is processed.

George Kaiser

StevenDL
Registered: Jun 4 2010
Posts: 15
I need to automate as much as possible. I saw that and found app.execMenuItem("SaveAs"); was the only function that didn't need folder level script (I think).

How do I fix the for loop or use a while loop so that the "oSubform1 has no properties" error doesn't occur? What I basically need is to hide up to 20 buttons that are created at runtime.