Feb 24, 2016, 5:07 PM
453 Posts
topic has been resolvedResolved

Calling a function in a separate JS file

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 9.0.1
  • Role: Developer
  • Tags:
  • Replies: 1

I have posted this on Stackoverflow as well but thought there might be someone here that could help

I have a button on an XPage that calls the function thisAction. The Page has the resource jsMain loaded and it contains the code below


function thisAction(msg:String){
    include ('jsSave.js')
    case "Save" :
        print("This action = " + msg);
        if (processAction()){
            print("processAction returned true");
            return true;
            print("processAction returned false");
            return false;
        print("In default msg is " + msg);
        return false;
        print("thisAction Failed in jsMain " + e.toString())

I have another js Script library called jsSave that has a function processAction. If I add the jsSave resource to my calling page all works well. However, for reasons that I wont go into I don't want to add the resource to my page but want to add it to my code in jsMain. The compiler wont accept the include statement though documentation I have found on line would suggest that it should be OK. I have found some examples where they modify the document header but I can't alter the source page. 

Any ideas?

Feb 26, 2016, 10:45 AM
453 Posts
The answer is easy

just add

import jsSave 

now all functions in the library jsSave are available in this library. No () "" or extension necessary.