0

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)
Cœur
  • 37,241
  • 25
  • 195
  • 267
Bill F
  • 2,057
  • 3
  • 18
  • 39
  • Why are you looking for a specific field across many forms? I am asking to see if there's a better solution to the actual problem. – Per Henrik Lausten Nov 04 '13 at 19:30
  • How about you rewrite it in Java? See here for sample code: http://openntf.org/XSnippets.nsf/snippet.xsp?id=reverse-engineering-notes-apps-sample-code – Mark Leusink Nov 04 '13 at 21:05
  • @Per Henrik - I need to present a list of forms to a client so that they can select one to create. I can't give them a list of all forms because that would be a mess. All of the forms that I want in the list contain a field that in this case I'm calling "ACIncludeForm". The List that I return will normally only contain a small number of the total number of forms in the database. The getForms returns a list that includes XPages, Custom Controls and SubForms. – Bill F Nov 04 '13 at 22:34
  • @Mark - I have been trying to avoid that route at the moment but perhaps it's time. – Bill F Nov 04 '13 at 22:35
  • 1
    Why do you not know the names of the forms in question beforehand? Are the users able to create forms themselves? If not, you have a set list already so why not just put them into a keyword field or something and use that as your list? – RoyRumaner Nov 05 '13 at 04:08
  • What if field is inside subform? – Frantisek Kossuth Nov 05 '13 at 07:31
  • @rrumaner - it is for an application that will be installed into many different databases where I would not be in control of the forms that were being created. – Bill F Nov 06 '13 at 20:29
  • @Frantisek - actually the field is in a subform and the subform must be inserted into each form that I want to list. Not in the code I ignore the subforms. – Bill F Nov 06 '13 at 20:31

2 Answers2

2

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.

Julian Buss
  • 1,114
  • 7
  • 14
  • That would work great. New forms would not be created often and once done a simple lookup in a view would get the values pretty quickly. Thanks – Bill F Nov 06 '13 at 16:56
  • Julian - just wrote a quick LS agent that populates a form and saves it for each matching entry then I do a view.getColumnValues(0) and stuff that into my viewScope works great. I'm using this list in several places, one is I have developed a generic "Create a New Entry" where the user selects one of the forms and I use the returned value to open the correct XPage. The database has dozens of forms in it but I don't want the end user to be able to create new documents with just any form. Created a throw away fields name that must be on each form that I want them to be able to create. – Bill F Nov 07 '13 at 02:16
0

Place the form list in a static field of a Java class. It will stay there for a long time (maybe until http boot). In my experience applicationScope values dissappear in 15 minutes.

Panu Haaramo
  • 2,932
  • 19
  • 41
  • @Pannu - Storing it in the sessionScope works fine, the issue is the most efficient way to get the subset of form names. – Bill F Nov 04 '13 at 22:36
  • OK, but I don't understand what kind of problem is 2-3 seconds processing time once a week. You can load them in the background so that no user will have to suffer waiting for 3 seconds :-) – Panu Haaramo Nov 05 '13 at 07:21
  • -just finished using the suggestion from Julian above and it turned a sluggish open of an XPage into a very nice crisp open. You are right 2-3 seconds is not much but it makes a hugh difference to the users experience. – Bill F Nov 07 '13 at 02:09
  • It would be simpler and faster if you store the list to memory. – Panu Haaramo Nov 07 '13 at 09:27