12 Replies Latest reply on Sep 27, 2015 6:02 PM by dinoapolito

    Portal filter based on an IF calculation

    dinoapolito

      Hi,

       

      I feel I should know the answer here so forgive me if it's obvious.

       

      I have a script that sets a global variable to either 1 or 0. ($$dGTLR)

       

      I want to the filter a portal based of the value of this variable

       

      If $$dGTLR = 1

      I want it to filter to show just one record (that's easy I can achieve that already)

       

      If $$dGTLR=0

      I don't want to filter -the portal should show all records.

       

      Many thanks as always

      Dino

        • 1. Re: Portal filter based on an IF calculation
          carlosilvia0

          Hi,

          look the image where I simulate a possible solution:

           

          1) Portal e button ( I change the $$dGTLR with global field value:

          1.png

           

          2) Portal details:

          2.png

          3) script details:

          Set Error Capture [ On ]

          Allow User Abort [ Off ]

          Set Variable [ $$dGTLR; Value:Parent::Global ]

          Refresh Portal [ Object Name: "Portal1" ]

           

          4) Browse mode with all portal row

          6.png

           

          5) Browse mode with $$dGTRL = 1

          5.png

          6) browse mode with $$dGTRL = 0

          7.png

          • 2. Re: Portal filter based on an IF calculation
            erolst

            You can simply write:

             

            $$dGTLR

            or

            not $$dGTLR


            EDIT: actually, just use


            $$dGTLR


            as your portal filter. The variable's value is itself regarded as either True or False, so no need to evaluate it again.

            • 3. Re: Portal filter based on an IF calculation
              BruceRobertson

              Your filter calculation doesn't make sense; because it make no reference to any of the related data of the child records.

              A portal filter calc is performed across every child record that the basic relationship includes.

              Let's say we have a Suppliers table; and a Products table.

              And a relation from Suppliers to Products where pkSupplierID = fkSupplierID

              We are on the Acme Plumbing supplier record.

              There are 971 Acme products.

              We could create a filter calc Products::TYPE = $$type

              And enter "faucets" in $$type

              And now we would only see the Acme products where Type = "faucet"

              • 4. Re: Portal filter based on an IF calculation
                erolst

                BruceRobertson wrote:

                 

                Your filter calculation doesn't make sense; because it make no reference to any of the related data of the child records.

                 

                It makes sense if you want to achieve a “now you see them (all), now you don't” toggle … (the question is if that makes sense by itself).

                • 5. Re: Portal filter based on an IF calculation
                  BruceRobertson

                  The calculation references no child data and therefore does nothing.

                  • 6. Re: Portal filter based on an IF calculation
                    erolst

                    BruceRobertson wrote:

                     

                    The calculation references no child data …

                     

                    That simply means that that calculation filters without regarding any child data …

                     

                    BruceRobertson wrote:

                    … and therefore does nothing.

                     

                    … but that doesn't mean it doesn't filter.


                    Create a variable $$display and filter a portal by just that expression; if $$display is False, you won't see any portal rows.

                    • 7. Re: Portal filter based on an IF calculation
                      BruceRobertson

                      Sorry, yes, you're right, for all or nothing filtering, a global variable with true or false value by itself does work. It doesn't show just one record though, as claimed at the top of the thread.

                      • 8. Re: Portal filter based on an IF calculation
                        dinoapolito

                        Thanks for all your suggestions guys.

                         

                        I think I'm more confused than ever! Maybe I have misstated my intention.

                         

                        What I need is not a toggle to show either all records or no records but a calculation that I use in my portal filter that will show one record or all records.

                         

                        If the global variable is True then I want it to show a particular record in the portal based on another variable. For example

                         

                        IF ($$dGTLR = 1;ProductID=$pID;"")

                         

                        I can get that part of it to work but in the same calculation I need it to show all records if $$dGTLR =0 (or not equal to 1 at least)

                        • 9. Re: Portal filter based on an IF calculation
                          BruceRobertson

                          Agreed.

                          Where is $pID set and what is the purpose of setting it?

                          Note that if you're using it for a portal filter, $pID will need to be a global variable $$pID.

                          Script variables ($pID) "evaporate" at the end of the script.

                          But if you want the filtering to occur only while a script is running, then in fact a script variable would be the right choice.

                          Maybe you should, for the moment, stop mentioning the calculations and instead describe what you are trying to do.

                          What is the user doing?

                          • 10. Re: Portal filter based on an IF calculation
                            dinoapolito

                            Agreed $pID will need to be global $$pID as it is captured in a script a couple of scripts back.

                             

                            Continuing the products example, the user will be selecting a product in a popover portal. (Lets call it Popover1/Portal1). At that point the productID, $$pID, is captured.

                             

                            When the user hits "Select", the $$pID is set, this popover is closed and another popover is opened.  This popover has another portal. (Lets call it Popver2/Portal2) And it's this portal that I want filtered  to show only the product with a ProductID=$$pID.

                             

                            This behaviour needs to be controlled by the global variable $$dGTLR. If $$dGTLR is True then the above needs to happen. If $$dGTLR is FALSE then forget the portal filtering because the user won't be entering Popover1/Portal1 at all but will be going straight to Popover2/Portal2 which will need to show all records.

                             

                            I can get the portal filtered when $$dGTLR is TRUE. That's all working. What I need is for the portal not to be filtered when $$dGTLR is FALSE.

                            • 11. Re: Portal filter based on an IF calculation
                              BruceRobertson

                              Then the expression could be:

                              $$dGTLR = 0 OR Products::ProductID = $$pID

                               

                              However; what is happening to $$pID when $$dGTLR is false?

                              If $$dGTLR = false does it mean that $$pID is empty?

                              If that were the case then it could be

                              IsEmpty( $$pID) OR Products::ProductID = $$pID

                              • 12. Re: Portal filter based on an IF calculation
                                dinoapolito

                                Yes, if $$dGTLR is false then $$pID would never get set and would therefore be empty.

                                 

                                I'll give that expression a go.