4 Replies Latest reply on Jan 8, 2009 6:46 AM by TomM

    Removing individual items from a multi-item field

    TomM

      Title

      Removing individual items from a multi-item field

      Post

      Hi,

       

      I'm trying to write a script to perform a search on a set of records which will then remove a particular item from a multi-item field if it is present.

       

      For example the field might be 'Colour' and some records may have multiple items in this field e.g. 'Red' 'Yellow' and 'Green'. How would I remove just 'Yellow' from this field on this record?

       

      I can see how to add text to a field, or how to re-define the fields contents, but can't seem to see how to edit the contents or remove part of the contents.

       

      Thanks.

      Tom. 

        • 1. Re: Removing individual items from a multi-item field
          Jens Teich
             Short answer: substitute( Colour ; "yellow" ; "" ).

          Longer answer needs info about how items are organized. Separated by newlines?

          Jens

          • 2. Re: Removing individual items from a multi-item field
            TomM
              

            Thanks. Is it actually called 'substitute'? I cant see it in my list of functions.

             

            The field is basically a pop-up menu box that allows multiple selections. When its viewed on the form each colour is on a new line yes.

             

            Tom. 

            • 3. Re: Removing individual items from a multi-item field
              Jens Teich
                 Yes there is a function called substitute(). Be sure not do confuse script steps and functions.

              Muliple items of value lists are separated by ¶. So you can use.

              * Substitute( "¶"& Colours &"¶" ; ["¶yellow¶";"¶"]; ["¶¶";""] )

              Homework: smarter version of this which does not leave newlines at beginning and end. Hint see here


              Jens




              • 4. Re: Removing individual items from a multi-item field
                TomM
                  

                Thanks again :-)

                 

                Its working great now, removing the line breaks when it should, and not when it shouldn't. For any body else's reference I did it like this:

                 

                Substitute ( Substitute ( Substitute ( Substitute ( Item::Colour ; "¶Yellow¶" ; "¶" ); "Yellow¶" ; "" ) ; "¶Yellow" ; "" ) ; "Yellow" ; "" ) 

                 

                This replaces, in this order:

                - 'Yellow' found inbetween two other lines ("" inserted in its place - otherwise the line above and below end up side-by-side)

                - 'Yellow' found with lines below it ("" inserted in its place)

                - 'Yellow' found with lines above it ("" inserted in its place)

                - 'Yellow' found on its own  ("" inserted in its place)

                 

                Might be a bit of a 'bodge' but seems to work :-) 

                 

                Thanks for your help.

                Tom.