Manage Learn to apply best practices and optimize your operations.

Nth position of a list

This tip describes how to get to a specific list item.

View member feedback to this tip.

It is easy to retrieve the first and last element of a list, but how do you return the nth position of a list?

The @Subset function can return the 1st position, the last position and X number of items in the list, but it can't return the nth value in the list.

The following code is an example of how to return the nth position of a text list.

First, make sure that your list actually contains at least the correct number of elements. Next, you use @Subset to return N number of elements. Finally, you grab the last element in that shortened list that corresponds to the element that you were looking for.

N := 10;
@If(@Elements(List) >= N; 
(List; N); -1); 


I used to use this technique all the time. Then I learned about the @GetMembers function introduced in R5. It is undocumented in R5, but is supposed to be documented in ND6.

The @GetMembers function gets a member from a list. The first parameter is the list and the second is a number corresponding to the position of the list member you want to get. Beats the @Subset(@Subset(list; n);-1) function in clarity and simplicity because you don't have to do any error checking. For n = 0 the nested @Subset method generates an error for which you need to trap. The @GetMembers function, however, simply returns a null value for n <= 0. Search for @GetMembers in the "Notes/Domino 4 and 5 Forum" on the Lotus Developer Domain Web site for more information.

-- Gardner R.

Do you have comments of your own? Let us know.

Dig Deeper on Lotus Notes Domino Formula Language



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury