Sunday, April 1, 2012

XPages type ahead step by step


Below are the steps for create type ahead in xpages

  1. Create a new notes form(not xpage) and name it "EmpForm"
  2. Create below fields in "EmpForm".
    1. EmpId(text, Editable) 
    2. EmpName(text, Editable)
  3. Save "EmpForm" and preview it Notes Client.
  4. Create these documents using "EmpForm"
    1. EmpId=1 & EmpName=Alice
    2. EmpId=2 & EmpName=Alisha
    3. EmpId=3 & EmpName=Barney
    4. EmpId=4 & EmpName=Alfred
    5. EmpId=5 & EmpName=Baker
  5. Create a new view "EmpView"
  6. Selection formula = SELECT form="EmpForm"
    1. First column = EmpName
  7. Preview the view in Notes Client, you should be able to see all created document here.
  8. Create a xpage "EmpXPage".
    1. Drop an Edit Box on it, name it "EmpNameTxt".
    2. Go to the type ahead section of "EmpNameTxt".
  9. Change below settings
    1. Check Enable Type Ahead.
    2. Mode = Partial
    3. Write below formula in suggestions box using computed value under blue diamond next to the box.
      1. @DbColumn(@DbName(), "EmpView", 1)
    4. Uncheck Case-sesitive 
  10. Preview "EmpXPage" in internet explorar.
  11. Type a in the text box, you will see suggestions.
Thanks for reading !!!

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.