4 Replies Latest reply on Jul 9, 2013 12:41 PM by rbogdanoff

    help with a simple script

    rbogdanoff

      I have a portal (DONATION) in a layout, and I want to display a comma separated list of all items from one field of each row of the porta in my layout. Should be pretty simple, right? Here is my script, it gets the number of rows correct (5 in this case) but it writes the data from DONATION::donation_type from the first row of the portal five times into my output field, rather than the data from rows 1-5.

       

      SetVariable [$portalRows; Value:Count(DONATION::donation type)]

      SetVariable [$counter; Value:1)]

      Loop

      ExitLoopIf [$counter > $portalRows]

      GoToPortalRow [No dialog; $counter]

      InsertCalculatedText[DONORS::display_all_donation_types; DONATION::donation_type]

      InsertText [DONORS::display_all_donation_types; ", "]

      SetVariable [$counter; Value:$counter+1]

      EndLoop

       

      What is wrong with this script??

        • 1. Re: help with a simple script
          breezer

          try using the function "List()"

           

           

          Let (

          type = List ( DONATION::donation_type ) ;

          Substitute ( type ; ¶ ; ", " ) )

          • 2. Re: help with a simple script
            DrewTenenholz

            rbogdanoff --

             

            Rather than fix the script, I'd go with a much simpler function:

             

            List ( DONATION::donation type ) // gets the values return separated

             

            Substitute ( List ( DONATION::donation type ) ; "¶" ; "," ) // gets the values comma separated

             

            n.b. this assumes that the portal on the layout has no special filtering which is different from the relationship that links to the portal records.

             

             

            Also, if you look up Ray Cologon's excellent XORValues ( ListA ; ListB ) function over at Brian Dunning's website, you can use it to show only unique values from the types of donations for the donor.

             

            Substitute ( XORValues ( List ( DONATION::donation type ) ; "" ) ; "¶" ; "," )

             

            will turn:  "Benefactor¶Donor¶Benefactor¶Angel¶Sustainer"

            into: "Benefactor,Donor,Angel,Sustainer"

             

            without any scripting at all.

             

             

             

            Also, if you really wanted to get fancy, you can look into the ExecuteSQL() function which can do all of the same tricks without even needing a linked table on the relationships graph (in case there really is a filter on the portal that you need there for a reason).

             

            -- Drew Tenenholz

            1 of 1 people found this helpful
            • 3. Re: help with a simple script
              rbogdanoff

              Like magic, thanks. Still learning the scripting language.

              • 4. Re: help with a simple script
                rbogdanoff

                Thanks for a great resource. I will be upgrading to FMP12 Advanced soon so I can't use the custom function until then.