FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.



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){
    try{
    include ('jsSave.js')
    switch(msg){
    case "Save" :
        print("This action = " + msg);
        if (processAction()){
            print("processAction returned true");
            return true;
            break;
        }else{
            print("processAction returned false");
            return false;
            break;
        }
    default:
        print("In default msg is " + msg);
        return false;
        break;
    }
    }catch(e){
        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.

 


FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.