Software Venture Consulting

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


Contact


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: 4.3  (42 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 11 comments

This function still has a big problem if there are empty lines in the original:

AddRemoveListItem( "a¶¶7¶6¶¶B"; "a")
Result:
7
6B

Bruce Robertson, Redmond
June 17, 2010 10:07am

This seems to solve the problem where empty lines in the original generate errors. Remove the empty lines first.

Let ([
novalue = IsEmpty ( FilterValues ( theList ; value ) );
newList = Substitute( theList; ["¶¶¶"; "¶"] ; ["¶¶"; "¶"] ) ;
listminusvalue = Substitute( "¶¶" & newList & "¶¶"; [¶ & value & ¶ ; ¶ ] ; ["¶¶¶"; ""] ; ["¶¶"; ""] ) ;
listplusvalue = List ( theList; value )
];
If ( novalue ; listplusvalue ; listminusvalue )
)

Bruce Robertson, Redmond
June 17, 2010 10:23am

Above has some errors also when adding to the list. I think this does it.

Let ([
value= GetValue( value; 1);
novalue = IsEmpty ( FilterValues ( theList ; value ) );
newList = Substitute( theList; ["¶¶¶"; "¶"] ; ["¶¶"; "¶"] ) ;
listminusvalue = Substitute( "¶¶" & newList & "¶¶"; [¶ & value & ¶ ; ¶ ] ; ["¶¶¶"; ""] ; ["¶¶"; ""] ) ;
listplusvalue = Substitute( List ( newList ; value ); ["¶¶"; "¶"] )
];
If ( novalue ; listplusvalue ; listminusvalue )
)

Bruce Robertson, Redmond
June 17, 2010 10:42am

This function does not work if you have a repeated value to be removed :
Example :

theList ="a¶b¶b¶b¶c";
value="b";

--> returns "a¶b¶c"

I suggest you use the Extraordinary function by Agnes Barouh : Filter list (http://www.briandunning.com/cf/771)

Or the following method :

// by Benoit Jolly - Active Développement
//
// RemoveValueFromList(listOfValues;value)
//
// Date : 07/06/2013
// Removes a value from a list EVEN if it is repeated multiple times
// No recursion is used
//
// The method is based on the method proposed by Debi Fuchs of Aptworks Consulting on http://www.briandunning.com/cf/897
//
//
// RemoveValueFromList("a¶b¶b¶b¶b¶b¶b¶b¶b¶c¶","b" ;) => "a¶c¶"


Let([
s = "######*q12sd6fa6z5fe16a5z1ef6a51zv65a1zv651az6e51fra6z5e16a1faz*##### ##" //very unlikely string
];
If(

//Check if unlikely string rears its head
Position( listOfValues; s; 0; 1 );

//If so, simulate an out-of-range error.
Evaluate( "Factorial( -1 )" );

// Otherwise, proceed to get rid of nulls
Substitute(
s & "¶" & listOfValues & "¶" & s;
[ "¶"& value & "¶" ; ¶ & s & ¶ ];
[ "¶"& value & "¶"; ¶ & s & ¶ ];
[ s & ¶; "" ];
[ ¶ & s; "" ];
[ s; "" ]
)
)
)

Benoit Jolly Active Développement, Lyon France
June 07, 2013 7:54am

Is there a way to keep a ¶ at the end of the list? I have no way of pulling individual rows from the list on the last row.

Currently, I am finding the ¶ at the end of each line, but the last line doesn't have a ¶ so I can't grab it.

this is what I am using to pull out individual lines

Left ( field ; Position ( field ; ¶ ; 1 ;1) )

Marty Enerson, Minneapolis/MN
August 09, 2016 2:07pm

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 6 + 8 =
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. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
2. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
3. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
4. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
5. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)
6. FixedFieldConverter ( Fieldname ; f1 ; f2 ; f3 ; f4 ; f5 ; f6 ; f7 ; f8 ; f9 ; f10 ; f11 ; f12 ; f13 ; f14 ; f15 ; f16 ; f17 ; f18 ; f1
  (Fri, Sep 15, 12:34pm)
7. ShannonEntropy ( text )
  (Thu, Sep 07, 5:59am)
8. LetterCount ( text ; summary )
  (Thu, Sep 07, 5:53am)

RSS Feed of Custom Functions