Reputation: 2087
It seems to me that this should be possible. In an XPages application I have two ServerSide JavaScript Libraries jsMain and jsSave. In the jsMain I have this Script:
function thisAction(msg:String){
try{
switch(msg){
case "Save" :
print("This action = " + msg);
if (jsSave.processAction()){
print("jsSave.processAction returned true");
return true;
break;
}else{
print("jsSave.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())
}
}
In a button on an XPage I call thisAction("Save")
and it invokes the thisAction function, now when the msg is Save I want to call the function processAction
but it resides in the JS Library jsSave. What I have above fails with the error:
thisAction Failed in jsMain 'jsSave' not found
So is there a way to tell this code that processAction is in an different SSJS Library?
Upvotes: 0
Views: 1614
Reputation: 876
Add
import jsSave
on top of your jsMain library, no quotes, no filename extension: you will be able to use functions declared inside jsSave from jsMain.
Upvotes: 6
Reputation: 1
Your page should include both the js libraries and jsSave library should be first.
<script src="jsSave.js"></script>
<script src="jsMain.js"></script>
Also please refer to modular javascript pattern.
Upvotes: 0
Reputation: 81
If jsMain was loaded first, you can't call a function in jsSave. However, you can call a function in jsMain from jsSave because it was loaded first.
Upvotes: 0
Reputation: 3593
Have you tried adding both libraries to your page? I'd think that would work. Alternatively I THINK at the top of the library you can do something similar to the LotusScript :
use "myLibrary"
I want to say you do :
import("jsSave");
But I'm not positive of the syntax. I'm sure I've done it once long ago though.
Upvotes: -1