Sunday, April 1, 2012

SSJS library functions in xpages

Create a SSJS script library:
Code-Script Libraries-New Script Library-Provide name and select type "Server JavaScript".

Create function in the library:
function testFunc(){
// your code goes here
}

In SSJS you are not required to define the parameters while creating function, you can write function below way and decide how many parameters you want to pass later.

Add this script library in your xpage
Open xpage-Resources-Add-JavaScript Library-Select library and click OK

Now you can call this function with your parameters or without parameters.
testFunc();
testFunc(Param1, Param2, Param3, Param3);

If you wish to access these parameters in your function you have an array with all the values available in order, name of the array is arguments.
You can find value of the first parameter Param1 in arguments[0]
second parameter Param2 in arguments[1]
and so on..

This is my first attempt on this, i will keep improving this.
You can also help me for the same. Thanks for reading.

No comments:

Post a Comment