3 Replies Latest reply on Apr 29, 2016 3:44 PM by erolst

    Select all checkbox

    ActiveControlsIT

      I have two checkboxes one with a value of '1' and the other a '0', I wrote a button in which it would select all of the checkboxes by changing the field to either a 1 or 0 accordingly. I am having two problems, one the loop I wrote in infinite but I feel as the code is right and it will add a new line when I want it to exit on last portal record. Second occasionally it will work but only if I click a field and than hit the button. I appreciate any help that I can get. Thank you.

       

      1.     Go to Portal Row [ First ]

      2.     Set Field [TableName:: MedCode_CheckBox ; 1 ]

      3.     Go to Portal Row [ Next ]

      4.     Loop

      5.          Set Field  [TableName:: MedCode_CheckBox ; 1 ]

      6.          Go to Portal Row [ Next; Exit after last ]

      7.          Allow User Abort [ On ]

      8.     End Loop

        • 1. Re: Select all checkbox
          erolst

          That doesn't work if the relationship the portal is based on allows record creation, because then there will always be a “last” row.

           

          Try

           

          Go to Object [ "portalObjectName" // give the portal an object name ]

          Go to Portal Row [ First ]

          Loop

            Exit Loop If [ IsEmpty ( TableName::primaryKey ) ]

            Set Field [ TableName:: MedCode_CheckBox ; 1 ]

            Go to Portal Row [ Next ]

          End Loop

          • 2. Re: Select all checkbox
            Extensitech

            As usual, "what erolst said"

             

            A question, though: What does this "selection" indicate? Is it truly an attribute of the related record in the portal, or is it only true in the context of the parent table?

             

            If the latter (which is a big if, but why I'm asking), you could have a field in the parent record for a list of "selected" keys from the related table. Then your checkbox could be a boolean based on whether the primary key in medcode is in the list field in the parent record (1 or 0) and the checkbox itself could be a button that adds or removes the key from the list stored in the parent table.

             

            An advantage here would be that your "select all" button could just set parentTable::selectedList to list (medcode::primaryKey), and "deselect all" could just clear parentTable::selectedList.

             

            It may be that "selected" really is an attribute of the table in the portal, though, in which case, pretend I didn't say anything.

             

            Chris Cain

            Extensitech

            • 3. Re: Select all checkbox
              erolst

              Extensitech wrote:

              A question, though: What does this "selection" indicate? Is it truly an attribute of the related record in the portal, or is it only true in the context of the parent table?

               

              If the latter (which is a big if, but why I'm asking), you could have a field in the parent record for a list of "selected" keys from the related table. Then your checkbox could be a boolean based on whether the primary key in medcode is in the list field in the parent record (1 or 0) and the checkbox itself could be a button that adds or removes the key from the list stored in the parent table.

               

              In that case one wouldn't even need a real field in the child table; just a flag icon with a Hide If condition of

               

              IsEmpty ( FilterValues ( Parent::selectionList ; Child::id ) )

               

              that does double-duty as a Set Field[] to add or remove the portal row ID from that list field.

               

              “Finding” all selected children could then be a Go to Related Record [ matching only } via a relationship of

               

              Parent:.selectionList = Child_viaSelection::id

               

              … and probably other methods.

               

              The usual embarrassment of riches that FM treats us to.