Expand my Community achievements bar.

How to get an Adobe trusted function javascript to save a pdf form even if fields are empty?

Avatar

Level 1

I have a form I have created in Livecycle designer which I want to save to a specific location using a combination of specific fields in the form. I have been able to do this by writing a trusted function and putting it in the adobe javascript file and then putting some code on a save button in the form. However, it may be that some of the fields (vfirstname and vsecondname) may be blank and i still want the form to save. Ideally i want to write an if statement to substitute those fields for other fields if they are blank but cant get the code to  work.

Working code in trusted function file


// SaveAs Function1



var mySaveDoc = app.trustedFunction(function(doc) {



app.beginPriv();



var vDate1 = event.target.xfa.resolveNode("form1.page1.Table1.Row1.leftsideofform.Timeanddate.Dateofcall").rawValue.toString();


var vfirstname = event.target.xfa.resolveNode(" form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.ClientFirstname").rawValue.toString();


var vsecondname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.Clientsurname").rawValue.toString();



var myPath = "/MGLCC01-SV/MGPdata/Mihomecare/testce/" + vDate1 +"_" + vfirstname + "-" + vsecondname + ".pdf";



// saveAs is the only privileged code that needs to be enclosed


doc.saveAs({cPath: myPath, bCopy: true, bPromptToOverwrite: true});


app.endPriv();


});


Working code on save button in form


form1.#pageSet[0].Newenquirymasterpage.Button1::mouseUp - (JavaScript, client)


var txt = form1.execValidate(); //This script will validate all required fields


event.target.mySaveDoc(event.target)


xfa.host.messageBox("Document has been saved to shared drive", "File Saved", 3, 1);


IF code for trusted function file that I cant get to work


// SaveAs Function1



var mySaveDoc = app.trustedFunction(function(doc) {



app.beginPriv();



var vDate1 = event.target.xfa.resolveNode("form1.page1.Table1.Row1.leftsideofform.Timeanddate.Dateofcall").rawValue.toString();



if (event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.ClientFirstname").rawValue == " ")


     {


         var vfirstname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Enquirer.EnquFirstname").rawValue.toString();


     }


     else


     {


         var vfirstname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.ClientFirstname").rawValue.toString();


     }


   


if (event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.Clientsurname").rawValue == " ")


     {


         var vsecondname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Enquirer.Enqsurname").rawValue.toString();


     }


     else


     {


         var vsecondname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.Clientsurname").rawValue.toString();


     }



var myPath = "/MGLCC01-SV/MGPdata/Mihomecare/testce/" + vDate1 +"_" + vfirstname + "-" + vsecondname + ".pdf";



// saveAs is the only privileged code that needs to be enclosed


doc.saveAs({cPath: myPath, bCopy: true, bPromptToOverwrite: true});


app.endPriv();


});


Can anyone suggest why the If code above doesn't work? or how i could get the form to submit even if the fields are blank?

0 Replies