Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Error in script when checking version

Avatar

Former Community Member
I'm placing some script in the form1::ready:form area and using JavaScript. I'm checking the version of Adobe Acrobat that is being used to lock folks out of using Acrobat 7.0 or earlier.



My script begins with:



var vappName = xfa.host.appType;

var vappVersion = xfa.host.version;



and uses the variable results to go through some if loops to hide and reveal things as appropriate. With these items at the beginning of my script, I get the error/warning message:



Script failed (language is javascript; context is xfa[0].form[0].form1[0])

Error: $host does not have property 'appType'



My code works as expected (hiding and revealing the proper items when I open the file in different versions of acrobat), so I'm not sure what the error is. I'm also using the same commands on a master page to fill in a text field with the version and type of software the user is using, and I get no errors there. Is the code in the wrong place?



If I replace the xfa.host.appType or xfa.host.version with text strings like:

var vappName = "Reader";

var vappVersion = 9;



then the code works as expected and has no errors, so there do not appear to be any problems with the if loops that follow.
7 Replies

Avatar

Former Community Member
Which version of Acrobat/Reader are you using when you get the problem? Can you send your form to livecycle8@gmail.com and I wil have a look.



I tried thise commands here and had no issues.

Avatar

Former Community Member
I've sent the form to you as requested - many thanks!



I'm using version 8 - I apologize for not mentioning this. It's the first thing I always ask students when they have problems with the form!



I have a bunch who are still using version 7 (reader or acrobat) and the form just does not work properly. They click through all of the error messages, and just keep on chugging.

Avatar

Level 10
Why not easily alert the users with a message when the form opens.

If they use a to old version, a message could inform them that the form cannot be used with this version.

By clicking OK the form closes.



Use this script in the docReady event of a page of your form.



if (typeof(app.viewerVersion) != "undefined")

if (app.viewerVersion < 9.1)

{

if(xfa.host.messageBox("This form cannot be used with this version of Adobe Reader!\rYou need Adobe Reader 9.0 or higher.", "Attention",1,0)==1)

{

event.target.closeDoc(true);

}

}

Avatar

Former Community Member
I didn't know of the multiple ways to find out the version of the viewer, so I started with the xfa commands. I'm self-taught for javascript and Live Cycle, so I've picked up what I've needed along the way. Is there a reason to use one type of command over the other (xfa.host vs. app.viewerVersion)?



What is the difference between putting the code in the docReady area versus the initialize area?



I cut my code from the initialize area and put it in the docReady area, and now I don't get an error!



And, by the way, if I closed the form without letting them enter stuff, I would have a big problem with some of our students! Hiding the form, and revealing a big help button is much friendlier.

Avatar

Former Community Member
The ways of doing it are basically the same thing .....the xfa commands wil only work in version of Acrobat/Reader that support xfa (version 6.05 and better). The app.viewerVersion is supported in version 5 and better. The docReady event happens after the FormReady (FormReady fires when the form dom is ready). The DocReady is the better event to use for this app.

Avatar

Level 10
1. Some JavaScript actions are not allowed to be executed until the form hasn't be initalized completely, like event.target.closeDoc(true); for example.



2. This was only a hint for you to avoid wasting time with programming different form actions depending of the users Reader version.



You can combine the version check with another action, like lauching the URL where the newest Reader can be downloaded.

That's very user friendly, I think.



if (typeof(app.viewerVersion) != "undefined")

if (app.viewerVersion < 9.0)

{

if(xfa.host.messageBox("Sorry, but this form requires Adobe Reader version 8.1 or higher!\rPress OK to close the form and download the newest version of Adobe Reader (freeware).\r\rThank you for your cooperation!", "Attention",1,0)==1)

{

event.target.closeDoc(true);

app.launchURL("http://get.adobe.com/de/reader/", true);

}

}

Avatar

Former Community Member
It took me a while to find a version 7 but I did....there was nothing wrong with your code but I was getting prompted to upgrade my version because you set the target version of the form for version 8. This means that any earlier version will get a prompt indicating that some features may not work properly beacuse you have targeted version 8. To fix this, go to File/Form Properties/Deafults and choose a target version that is inline with what you are trying to do.



Make sense?