Selecting Items from a List

Given a list (not a portal), users may need to select certain records for later processing (mail merge, print list, etc.).  Using an indicator field on each record is not an option in a multi-user system – User B may unset the flag set by User A – so the solution is to use a global variable to hold the keys of selected variables.  The global variable is session-specific, so there’s no danger of users getting in each other’s way.

The Components

  • The global variable to hold the list of selected people – $$SelectedPeople
  • The key of the record that user has selected – say PPL::PPL__kp_ID.
  • The custom function that maintains the list in the variable – AddOrRemoveSelectedItem (list,value).  (It needs to detect whether user has already selected the item.  If so, it must be removed from the list.  If not, it needs to be added to the list.)
  • A script to run when the user clicks on the select button – Select a Person.

The Custom Function

The CF looks like this:

The first bit creates a variable, “newList”, that will be used if the value is already in the list, i.e. in the “If” statement.  (The leading and trailing “¶” are there to ensure that the PatternCounts do actually find “PPL1981” and not “PPL198”.)

The If statement itself reads:

“If the value is already in the list, take the new list (i.e. the existing list, with a leading and trailing “¶”, but minus the value selected) and remove the leading and trailing “¶”.  If the value is NOT already in the list, add it to the end, with a “¶” before it.  If the list is empty (i.e. this is the first item selected), don’t add the “¶”.”

The Script

The script is really just a one-liner to set the variable, with a freeze and refresh of the window:

(The parameter (GSP(1)) is the key field of PPL. )

Conditional Formatting

To show the user which item(s) s/he has selected, apply conditional formatting to the list.  Use the same checking as in the CF, i.e.:

PatternCount( ¶ & $$SelectedPeople & ¶; ¶ & PPL::PPL__kp_ID & ¶)

i.e. if the item exists in the list, apply the highlight (or whatever formatting is suitable).

Selecting ALL Records

If user wants to select everyone in the found set, the process is very straightforward.  Here’s the script that runs if user opts to “Select All”:

We go to Form View (important, because in List View the whole thing is VERY slow), then loop through all records, adding each one to a script variable.  After that, plonk the list into the global variable.  (Using a script variable for the loop seems to make the whole thing faster.)

Advertisements

One Comment on “Selecting Items from a List”

  1. […] realised the error of my ways, I now use the technique described in “Selecting Items from a List“, which basically puts the primary key of each selected item in a global variable (say […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s