7 Replies Latest reply on Apr 4, 2017 9:33 AM by ezeitgeist

    Hide button when a field in a related table is not empty?

    ezeitgeist

      I have 2 tables (User table & B Table) linked by User_ID.  B Table has its own serial_ID and Location_ID.

       

      I want to hide a button when the Location is looked up and a related record already exists for that Location (I have an Auto-filtering Search Portal setup and when a portal row is selected, a $LocationID variable is stored).

       

      My thought was hide object when: User table::User_ID = B Table::User_ID and B Table::Location_ID=$LocationID and not IsEmpty(B Table::serial_ID).

       

      But when I put in the above it just stays hidden the entire time. Where is my error?

        • 1. Re: Hide button when a field in a related table is not empty?
          philmodjunk

          Is this button in the portal or on the layout?

           

          Seems like you can simplify to:

          B Table::Location_ID=$LocationID and not IsEmpty(B Table::serial_ID)

           

          But that doesn't explain why it's always True and thus always hidden. You might need $$LocationID instead of $Location so that the value persists when the script exits. But again, that doesn't explain why the expression is always True.

           

          Describe layout and portal here (Tableoccurrences, relationshps, filters....) as well as answering my original question as to where you have located the button for this.

          • 2. Re: Hide button when a field in a related table is not empty?
            ezeitgeist

            Button (that I want to show/hide) is on the layout.

             

            I have a button on the portal row that, when selected, stores the Location_ID into the $LocationID variable.

             

            Table relationships:

            User Table <--User_ID--> B Table <--Location_ID--> Locations Table

            I also have a Locations ALL TO connected many-to-many to the Interface (which is in turn connected to the User Table).

             

            I want the button to stay hidden UNTIL $LocationID is for a Location that does NOT already have a record. Then I want it to appear. (I am trying to create a situation where the User can only add one record in B Table per location. If I hide the button that allows them to add a record to B Table when a record for that Location already exists or $Location is empty, they cannot add a new one. There may be a better route for this. This is the one I thought up currently. Open to alternative routes.)

            • 3. Re: Hide button when a field in a related table is not empty?
              philmodjunk

              That doesn't really seem workable.

               

              You appear to have these relationships:

               

              User Table ---< B Table >---- Locations Table

               

              By placing the button on the User table and not in a portal row, the expression evaluates from the context of the current User Table record:

              User table::User_ID = B Table::User_ID ---> this will be true as long as there is at least one related record in B table.

              B Table::Location_ID=$LocationID ----> this will be true if the first related record in B Table has a value in Location_ID that matches $LocationID. If both are null, this should also evaluate as true.

              not IsEmpty(B Table::serial_ID) ----> This will be true if there is at least one related record in B Table

               

              Note that any subsequent related record in B Table are not part of this calculation, only the first related record.

              • 4. Re: Hide button when a field in a related table is not empty?
                BruceRobertson

                I have a button on the portal row that, when selected, stores the Location_ID into the $LocationID variable.

                 

                Sorry, that is impossible.

                That is a script variable.

                You cannot "store" anything in it.

                A script variable empties as soon as the script stops.

                • 5. Re: Hide button when a field in a related table is not empty?
                  ezeitgeist

                  That makes sense, I need to just put the button in the portal.

                  • 7. Re: Hide button when a field in a related table is not empty?
                    ezeitgeist

                    I fixed by reworking the layout. Changed it so that the layout table is Location, created a self-join so I could display layouts in a portal, and then created a different portal for links to Location table (related by Location_ID and User_ID). I just use $$UserID to add the User_ID to the related table and filtering to keep it to the user viewing the table.