A quick reminder on how I got a working snippet of code to store the entries in the lookup already selected, check against another table/form for valid options, repopulate the list with the selected item and filtering the options available for selection.
Why?
This was for a multi lookup with staff as the list entries. The lookup needed to filter against various forms such as Staff Rotas, Leave Requests, Qualifications and some others.
How?
The aim/objective is the following:
- Store what was already selected in the lookups
- Clear the lookups list
- Restore what was originally selected as selected.
- Repopulate with a filter list of options (not selected but available)
// ************************************************************* // store already selected entries // if(!isnull(input.myLookup)) { // remember remember the 5th of november l_RememberLookup = List(); if(input.myLookup.size()>0) { for each v_SelectedLookup in input.myLookup { l_RememberLookup.add(v_SelectedLookup); } } } // // clear lookup clear myLookup; // // get list of all valid entries l_AllowedEntries = {}; for each v_AllowedID in myForm[ID != 0] { v_thisID = v_AllowedID.ID; l_AllowedEntries.add(v_thisID); } // // restore item in lookup input.myLookup = l_RememberLookup; // // repopulate lookup options (not selected items) for each r_EntryID in l_AllowedEntries { input.myLookup:ui.add(r_EntryID); }
- // *************************************************************
- // store already selected entries
- //
- if(!isnull(input.myLookup))
- {
- // remember remember the 5th of november
- l_RememberLookup = List();
- if(input.myLookup.size()>0)
- {
- for each v_SelectedLookup in input.myLookup
- {
- l_RememberLookup.add(v_SelectedLookup);
- }
- }
- }
- //
- // clear lookup
- clear myLookup;
- //
- // get list of all valid entries
- l_AllowedEntries = {};
- for each v_AllowedID in myForm[ID != 0]
- {
- v_thisID = v_AllowedID.ID;
- l_AllowedEntries.add(v_thisID);
- }
- //
- // restore item in lookup
- input.myLookup = l_RememberLookup;
- //
- // repopulate lookup options (not selected items)
- for each r_EntryID in l_AllowedEntries
- {
- input.myLookup:ui.add(r_EntryID);
- }
Additional Note(s):
- If removing elements, even if you are using Creator v5, use removeElement() and NOT remove() which got me stuck for a while. This is for error