2.
In the Script Editor, from the Show list, select one of the events that apply to the object. The event you choose specifies when the script will execute. If you are writing a calculation or script that affects an object that does not support events, you must add your calculation or script to a form design object that does support form events. For example, using the new button object, select the click event in the Show list.
You can choose to run calculations or scripts on your client-based application (for example Acrobat or a web browser) or on your server-based process (for example, LiveCycle Forms ES). When set to Client, processing of calculations and scripts initiates after the form renders. When set to Server, processing of calculations and scripts initiates during the form rendering process. Previewing your form by using the Preview PDF tab simulates opening the form in Acrobat; therefore, scripts set to run at Client or Client and Server execute.
Note:
Selecting Client And Server from the Run At list causes a script to execute in either the client application or the server application, depending on which application is used to process the form.
5.
In the Script Source field, insert your FormCalc calculation or JavaScript script. You can take advantage of the statement completion functionality of LiveCycle Designer ES to help you create reference syntaxes for your calculation or script. For example, add the following JavaScript script to the new button object:
xfa.host.messageBox(“Hello World!”, “Creating a new script”, 3);
6.
After you complete your form design, test and debug your calculations and scripts before putting them into production. For example, for the new button object, preview the PDF of the form using the Preview PDF tab. Click the button object to display the message box specified in step 5.
See also 

To create a calculation or script