Software Venture Consulting
ToMarket

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Brian Dunning
Contact me | vCard


Brian on CNN
Brian on CNN


Brian on CBS Radio


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

AddRemoveListItem ( theList ; value )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 3.8  (15 votes)
  Discuss this Custom Function

David Head, uLearnIT
http://www.ulearnit.com.au/

Add a value to or remove an values from a list of values

Sample Input:
AddRemoveListItem ( "apple¶banana¶cherry" ; "banana" )
Sample Output:
"apple¶cherry"


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

This function will add an item to a list if it does not already exist; otherwise the item is removed from the list.

Update: the listminusitem was adjusted to account for instances where the value being removed is also the end of any value of the list. This now works by wrapping the list in double ¶, substituting out the value, and finally substituting out the double ¶ at the end. Also reversed the logic of the item test (novalue). Also now consistent about referring to "value" instead of "item" in all variables.

Further update: added substitution of three ¶ to ensure that when the very last value is removed, the list is null. Thanks to Andrew McCallum.

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

5 most recent comments | Show all 6 comments

How about:

Let (
nope = IsEmpty ( FilterValues ( theList ; value ) ) ;

If ( nope ;
List ( theList; value );
Substitute( theList & ¶; value & ¶; "" )
)
)

Bruce Robertson, Redmond WA
March 09, 2009 10:57am

This function is does not work 100%. If you had "apple banana pineapple" and the item is "apple", you would end up with "banana pin".

Bernard Cheang, Singapore
March 09, 2009 5:23pm

Hi Bruce
I had something like that early in testing. I tested yours but it leaves a trailing return every time you remove an item. That was the purpose of the second listminusitem setting. ;)

Hi Bernard
Good catch! I have updated the CF to trap for cases where the value being removed is the end of the last value. I have used <EOL> to signify end of list. If you were happy to limit the use of the CF to version 10+ then you could use some formal ASCII character with the Char function. But I think this should be sufficient for most data. Thanks for the feedback.

David Head, Darwin Australia
March 10, 2009 12:07am

Hmmm, further testing revealed the problem was not just if the value being tested was the end of the last value - it occurred if it was the end of ANY value.

I have updated the listminusitem variable expression to fix this issue. Seems to work consistently now.

Note that this CF does not return any trailing returns in the result.

David Head, Darwin Australia
March 10, 2009 1:15am

Good job, David. I was looking for a similar function. Didn't have time to fix it myself. Thanks.

Bernard Cheang, Singapore
March 10, 2009 5:34pm

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 2 + 2 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. GeoBox(latitude;longitude; radius)
  (Mon, Mar 15, 11:04am)
2. MonthNameList ( start; number; short )
  (Sun, Mar 14, 11:45pm)
3. matchListAB( ListA ; ListB; match_Value; match_operator ; getN )
  (Sun, Mar 14, 10:29pm)
4. Bin2Hex ( binary )
  (Sat, Mar 13, 10:08pm)
5. SlideView (text)
  (Sat, Mar 13, 8:40pm)
6. HashFNV1a64 ( text ; empty )
  (Sat, Mar 13, 6:23pm)
7. HashFNV1a32 ( text ; empty )
  (Sat, Mar 13, 5:55pm)
8. XORbin( bin0 ; bin1 ; "" )
  (Sat, Mar 13, 4:35pm)

RSS Feed of Custom Functions