Contact TLCC

Use JavaScript libraries to share code Click here to see all the Developer/Admin Tips

Date tip published:08/25/2003
Description:In Release 6, JavaScript procedures can be placed in a script library which is stored in the Domino database. Procedures in the JavaScript library can be accessed from a form, subform, or page in the current database or another database. This allows you to share common JavaScript functions commonly used to validate information and manage windows.


To learn more about JavaScript in Notes Domino 6 use the following link:

JavaScript for Notes Domino 6


JavaScript Libraries

In Release 6, JavaScript procedures can be placed in a script library which is stored in the Domino database. Procedures in the JavaScript library can be accessed from a form, subform, or page in the current database or another database.

This tip was taken from TLCC's JavaScript for Notes Domino 6 course.

This comprehensive course will make you a JavaScript expert in a mere 3 days. Easy, convenient and cost-effective, it will thoroughly prepare you to use JavaScript and for the IBM/Lotus certification exam which will allow you to become a IBM Certified Advanced Developer - Lotus Notes and Domino 6.

In this course you will learn the basics of the JavaScript programming language, what it can do for you and how you can incorporate it into your Domino applications. First, you learn the fundamental building blocks of the core JavaScript language, its syntax and how it relates to HTML. You then become familiar with the JavaScript Object Model and how JavaScript employs object-oriented programming techniques for working with information on web pages. You will use Client-Side JavaScript objects, methods and events to create useful and interesting interfaces for your Domino web pages. Learn how to recreate Notes Client features that Domino can not port to web browsers such as dialog boxes and opening windows. Understand browser compatibility and the differences between the Notes client, Netscape browser, and Microsoft browser and how to handle them. This course is designed exclusively for Domino developers and includes many demonstrations and activities.

Click here for more information on TLCC's JavaScript for Notes Domino 6 course.

Advantages
Advantages of JavaScript Libraries

Script libraries are an excellent tool for storing code segments in your application. They offer the following advantages:

    • JavaScript libraries allow you to write a procedure once and then access that procedure from anywhere in the database. This can greatly reduce the amount of code required for the database.
    • JavaScript libraries can be accessed from another database. Reusable JavaScript procedures can be created and maintained in a "central" code database.
    • When a procedure in a JavaScript library needs to change, all of the changes occur in one place. This reduces maintenance time.
    • JavaScript libraries work in Notes applications and web applications.
    • Reusing procedures in JavaScript libraries supports team development.

Procedure: Creating a JavaScript Library

Follow these steps to create a JavaScript library:

1. In Designer, open the database for the library.

2. In the Design pane, expand the Shared Code section and click on Script Libraries.


3. Click on the [New JavaScript Library] button to create the library and open the JavaScript editor.



4. In the JavaScript editor, add the functions for the JavaScript library.




5. You will be prompted for a library name when you save or close the editor. Enter the JavaScript library name and click [OK] to save the new library.




Procedures: Using a JavaScript Library

Before calling the functions from a JavaScript library, the library must be inserted in a page, form or subform. There are two ways to insert a JavaScript library resource. A JavaScript Library can be inserted into the design element's JavaScript header or directly on the page or form. See the tip at the end of this page for guidance on when to insert a JavaScript library directly onto a page or form instead of the JavaScript header.

Follow these steps to insert a JavaScript library in the JavaScript Header:

  1. Position the cursor in the JS Header event in the page or form that will use the library.

  2. Select Create | Resource | Insert Resource... from the menu.




  3. Select the database where the JavaScript library is located.
    1. Select JavaScript Libraries for the Resource type.
    2. Select the JavaScript library to insert from the Available resource.
    3. Click the [OK] button to insert the library.

  4. A resource object for the JavaScript library is placed in the JS Header event. Multiple libraries can be inserted.


When this form is viewed using a web browser the following source code is sent to the browser:
<head>
<script language="JavaScript" type="text/javascript" src="/tlcc/6upd/6devupd1/6updwrkb.nsf/ValidateFieldsJS?OpenJavascriptLibrary">
</script>
</head>



Follow these steps to insert a JavaScript library directly on the page or form:
  1. Position the cursor on the page or form where the library should be inserted.

  2. Select Create | Resource | Insert Resource... from the menu.




  3. Select the database where the JavaScript library is located.
    1. Select JavaScript Libraries for the Resource type.
    2. Select the JavaScript library to insert form the Available resource.
    3. Click the [OK] button to insert the library.


  4. A resource object for the JavaScript library is placed directly on the page or form. The script icon ( ) indicates the location of the JavaScript library on the form. Multiple libraries can be inserted.


When this form is viewed in a web browser the following source code is sent to the browser and placed in the BODY section of the web page at the position where inserted:
<script language="JavaScript" type="text/javascript" src="/tlcc/6upd/6devupd1/6updwrkb.nsf/ValidateFieldsJS?OpenJavascriptLibrary">
</script>

    Tip
    When to use the JS Header vs. inserting directly on the form or page?

    Normally you should insert your JS library into the JS Header. In the initial release of Notes 6 (beta versions and possibly 6.0) JavaScript libraries inserted into the JS Header did not work for the Notes client. They only worked on the web browser clients. The only solution to get a JS library to work for the Notes client was to insert it into the form and not the JS Header. TLCC has confirmed JS Libraries inserted into the JS Header work for the Notes client for Notes 6.0.1 and higher.