Try OpenEdge Now
skip to main content
Application Developer's Guide
Developing an application : Using JavaScript in a workstep : Integrating JavaScript : Managing collections of commonly used JavaScript code
 
Managing collections of commonly used JavaScript code
You might find yourself using certain JavaScript functions repeatedly in a number of different process templates. To avoid duplicating the definition and compilation of this JavaScript code in multiple processes/worksteps, you can put these commonly-used code elements in a JavaScript file called common.js in the OEBPS_HOME\BPServer directory.
You may define a function and place it in the common.js file. If this is the first function created, then you must create the common.js file first. All JavaScript functions defined in OEBPS_HOME\BPServer\common.js are compiled during the start-up of the BP Server and are ready for use from any JavaScript code.
Important: Since the JavaScript defined in the common.js file is kept in memory until the BP Server is shut down, you should only add those JavaScript functions that is used by the maximum number of the applications, processes, and worksteps.
For example, if most of your applications access CHARACTER dataslots for URLs, and you want to provide a JavaScript function to download the contents and search for specific data, then you can add the following script to the common.js file:
function getURLContent() {
         var url = "http://www.savvion.com";
         var contents = "";
         var nextLine = "";
         var urlObj = new java.net.URL(url);
         if (urlObj == null) {
            return "";
         }
         var ustream = new java.io.DataInputStream(urlObj.openStream());
         if (ustream == null) {
            return "";
         }
         while (true) {
            nextLine = ustream.readLine();
            if (nextLine == null) {
              break;
            }
            contents += nextLine + "\n";
         }
         ustream.close();
         return contents;
}getURLContent()
Note: Do not use any parameters inside this function.