Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Create Javascript functions in Designer

Avatar

Former Community Member
Hi,



I used to design forms using Adobe Acrobat, I used to write global functions defined on the form level (functions used any field on the form).



Now, I want to do the same thing in forms created using LiveCycle desinger 7. I couldn't find where (if it exists) can I define global functions. Any ideas?



Thanks in advance.
6 Replies

Avatar

Former Community Member
You can place functions in a script object as follows:



Right click on the highest level object in the Hierarchy palette.



Left click on the 'insert script object' option.



The script object will be inserted at the bottom of the Hierarchy - simply add your functions to it.



Rename the script object if desired.



Suppose you have a script object called 'SO' and a function within it is called 'Fred' - then within the form istself you can refer to the function as 'SO.Fred'.

Avatar

Former Community Member
Hi Smith,



Thanks for the reply. It helped. But now I am facing 2 problems:



1. I created a new script object and called it

b myFunctions

. Inside the script, I added the following function:



b function fncHelloWorld()



b {



b xfa.host.messageBox("Hello World!");



b }



I am calling the function from a button click using the script below but nothing is happenning.



b myFunctions.fncHelloWorld();



Even the method name

b fncHelloWorld

is not appearing in the (intellisence) list of methods/properties after I type "

b test.

". Any clue?



2. I created another new script object and called it

b sayHi

. Inside that script, I placed the Java script:



b xfa.host.messageBox("Hi");



I am calling it from a button click using the following script:



b xfa.host.messageBox("Before calling method...");



b sayHi();



b xfa.host.messageBox("After calling method...");



The first message box "Before calling method", and the message box "Hi" are shown, which means the function is being called. However, the last message "After calling method..." is not shown. In fact, anyother script after calling the function is not working. Moreover, I need to create functions like in the first scenario because I need functions that takes parameters.



Your help is highly appreciated.

Avatar

Former Community Member
Make sure the option is on for Acrobat to show you the error message when something goes wrong in a script. Hopefully that will give you further insight into what is going wrong. You do this in Acrobat under Edit->Preferences->JavaScript->Show Console on errors and messages.



H.

Avatar

Former Community Member
I copied your Hello World function onto one of my forms and it worked for me.



I don't really have any definite answers being a Javascript novice myself.



Usually when script fails to work it is due to a syntax error.



Another cause can be the the wrong scripting language has been specified - perhaps FORMCALC is specified somewhere instead of JAVASCRIPT.

Avatar

Former Community Member
Sharko,



1) I am sure if you change the 'language' to 'javascript', it should work. Also, intellisense does not seem to pick up all the functions' names in the script object. In fact, it never did. Hopefully, this will be improved in future version of Designer.



2) You do not need to create another script object. You can define multiple functions within one script object.

Anyway, if you create a new script object (let's say "myScript"),

then this is what you should have put on the 'click' event of your button.



xfa.host.messageBox("Before calling method...");

myScript.sayHi();

xfa.host.messageBox("After calling method...");



and remember to change to 'language' to 'javascript' in the right top corner of Designer GUI.