Search code examples
xpagesxpages-ssjs

getting a list of forms that contain a specified field, is there a better method


The following code is a script object on an XPage in it I loop through an array of all the forms in a database, looking for all the forms that contain the field "ACIncludeForm". My method works but it takes 2 - 3 seconds to compute which really slows the load of the XPage. My question is - is there a better method to accomplish this. I added code to check to see if the sessionScope variable is null and only execute if needed and the second time the page loads it does so in under a second. So my method really consumes a lot of processor time.

var forms:Array = database.getForms();
var rtn = new Array;
for (i=0 ; i<forms.length; ++i){
    var thisForm:NotesForm = forms[i];
    var a = thisForm.getFields().indexOf("ACIncludeForm");
    if (a >= 0){
        if (!thisForm.isSubForm()) {
            if (thisForm.getAliases()[0] == ""){
                rtn.push(thisForm.getName() + "|" + thisForm.getName() );
            }else{
                rtn.push(thisForm.getName() + "|" + thisForm.getAliases()[0] );
            }
        }
    }
    thisForm.recycle()
}
sessionScope.put("ssAllFormNames",rtn)

Solution

  • One approach would be to build an index of forms by yourself. For example, create an agent (LotusScript or Java) that gets all forms and for each form, create a document with for example a field "form" containing the form name and and a field "fields" containing all field names (beware of 32K limit).

    Then create a view that displays all these documents and contains the value of the "fields" field in the first column so that each value of this field creates one line in this view.

    Having such a view, you can simply make a @DbLookup from your XPage.

    If your forms are changed, you only need to re-run the agent to re-build your index. The @DbLookup should be pretty fast.