14 Replies Latest reply on Jul 24, 2013 9:53 AM by danlee

    Cannot figure out script for layout tabs for date ranges and portals...

    danlee

      Title

      Cannot figure out script for layout tabs for date ranges and portals...

      Post

           I have been trying to find a solution for this but cannot get anything to work.  Under Pic #2, within the Calories and Measurements tab I placed a date field, BodyAgeDate, with left and right arrows that will go through all the dates from table MeasurementsData for that particular client.  How can I set that up and have all those data appear in the fields of Calories and Measurements tab?  Also is there a way that I can click any of the row of data in the portal and have those data fill their fields in the Calories and Measurements tab too?
            
            
           Thank you

        • 1. Re: Cannot figure out script for layout tabs for date ranges and portals...
          philmodjunk

               First key concept that you may or may not already know is that you aren't limited to a single Tutorial: What are Table Occurrences? in your relationship graph (pic #1) for any given table and thus you can set up multiple relationships between the same two tables by using different occurrences of the same data source table.

               Since you have a date field in your measurements table, you can set up two relationships from clients to two different occurrences of MeasurementsData:

               MeasurementsData|Date----------Clients-------<MeasurementsData

               Clients::_pkClientID = MeasurementData::_fkClientID

               Clients::_pkClientID = MeasurementData|Date::_fkClientID AND
               Clients::gMDate = MeasurementsData}Date::DateField

               gMDate would be a field with global storage in my example, (but it does not have to be global).

               Your measurements fields on the tab would be selected from MeasurementsData|Date.

               The following script would update gMDate with the next measurement date from MeasurementsData:

               IF [ $$Mnumber < Count ( MeasurementsData::_fkClientID ) ]
                   Set Variable [$$Mnumber ; Value:  $$Mnumber + 1 ]
                   Set FIeld [ Clients::gMDate ; GetNthRecord ( MeasurementsData::DateField ; $$Mnumber ) ]
               End If

               A button in your portal row can be set up to perform this script:

               Set Field [Clients::gMDate ; MeasurementsData::DateFIeld ]
               Set Variable [$$Mnumber ; Value: Get ( ActivePortalRowNumber ) ]-->keeps date set of controls in sync

          • 2. Re: Cannot figure out script for layout tabs for date ranges and portals...
            philmodjunk

                 Ohyes, forgot to include:  For an explanation of the notation that I am using, see the first post of: Common Forum Relationship and Field Notations Explained

            • 3. Re: Cannot figure out script for layout tabs for date ranges and portals...
              danlee

                   Thank you for your help.  I am really new to all this so I am a little lost.  Do I need to create another table, MeasurementsDatalDate?

                   Is the DateField another field that I create in MeasurementsData table or is it the same as BodyAgeDate field?

                    

                   Thank you in advance

              • 4. Re: Cannot figure out script for layout tabs for date ranges and portals...
                philmodjunk

                     Please click the link to a thread on Tutorial: What are Table Occurrences? that I provided in the first post. MeasurementsData|Date is a new table occurrence that has the same data source table as MeasurementsData.

                • 5. Re: Cannot figure out script for layout tabs for date ranges and portals...
                  danlee

                       Thanks got it!  :)  But when I created second MeasurementsData table and create a relationship between Clients::_pkClientID = MeasurementData2::_fkClientID AND Clients::gMDate = MeasurementsData2::BodyAgeDate and go and change the fields on the tab to match the MeasurementsData2 it does not allow me to enter any data into those measurement fields :(  Don't know what I am doing wrong.

                  • 6. Re: Cannot figure out script for layout tabs for date ranges and portals...
                    danlee

                         I got everything set up and am now able to input data into the fields (just had to check, "Allow creations of records..." :-)

                         But when I add type into the fields it makes multiple copies of the data.  I changed every single field in the Calories and Measurements tab, even BodyAgeDate field to MeasurementsData2.  I have a popup window when you click the heart icon to appear to enter new data for that ClientID and changed all of them to point to their related MeasurementsData2 fields.

                         Don't know what I am doing wrong.  Please any help is much appreciated.

                    Pic #1

                    Pic #2

                    Pic#3

                    • 7. Re: Cannot figure out script for layout tabs for date ranges and portals...
                      philmodjunk

                           Did you duplicate the table occurrence or did you duplicate the data source table?

                           You needed to duplicate the table occurrence, not the data source table. You create duplicate table occurrences in Manage | Database | Relationships--not in Manage | Database | Tables.

                           The problem may lie with the script that is performed when you click the heart icon or the script performed when you click OK in that pop up window. I'd guess that you need to modify that script to check for existing records with the same specifed date. You may even want to have two buttons instead of one that pass slightly different data as a script parameter to the same script. One button creates a new blank record and the other opens the same window with the data from the currently selected measurementsData record for review/editing.

                      • 8. Re: Cannot figure out script for layout tabs for date ranges and portals...
                        danlee

                             I duplicated the table occurence.  I know why those dates were repeating.  The portal was linked to DataMeasurements except for DataMeasurements2.  Once I changed that it did not duplicate the rows.  But It is still not working. :(  I get an error in the layout that has the Green Check mark when trying to enter info in any field; "This operation cannot be performed because one or more required related records are not available and cannot be created.  All that check mark does in that layout is close that window.  In the layout that has the heart icon when I enter in data it erases the old data in the portal.  If I try to enter more data nothing is created in the portal or saved in that layout tab.  But when I go to the related table all the measurements data have been created.  Here is the script for that heart icon:

                        https://dl.dropboxusercontent.com/u/21551505/Screen%20Shot%202013-07-16%20at%209.02.09%20PM.png

                               

                        • 9. Re: Cannot figure out script for layout tabs for date ranges and portals...
                          philmodjunk

                               Sounds like the layout you use with this pop up window is not based on the correct table occurrence. Check and see what is specified in Layout Setup | Show Records From.

                          • 10. Re: Cannot figure out script for layout tabs for date ranges and portals...
                            danlee

                                 Got everything to work!!!  Just one problem...

                                 This gives me the next past date.

                            IF [ $$Mnumber < Count ( MeasurementsData::_fkClientID ) ]
                                Set Variable [$$Mnumber ; Value:  $$Mnumber + 1 ]
                                Set FIeld [ Clients::gMDate ; GetNthRecord ( MeasurementsData::DateField ; $$Mnumber ) ]
                            End If

                                 I tried changing the "<" to ">" and "...+ 1" to "... - 1" but can not get the next forward date.   Can you let me know what I am doing wrong?

                            • 11. Re: Cannot figure out script for layout tabs for date ranges and portals...
                              philmodjunk

                                   I'd need to know the context in which this script is performed.

                                   On what table occurrence is the layout based? (What layout is current when this script is performed?)

                                   Why do you use the variable $$Mnumber here?

                                   What value does $$Mnumber have before these script steps are executed?

                              • 12. Re: Cannot figure out script for layout tabs for date ranges and portals...
                                danlee

                                     Hi,

                                     I am using the script that you wrote out towards the beginning of this thread: 

                                First key concept that you may or may not already know is that you aren't limited to a single Tutorial: What are Table Occurrences? in your relationship graph (pic #1) for any given table and thus you can set up multiple relationships between the same two tables by using different occurrences of the same data source table.

                                Since you have a date field in your measurements table, you can set up two relationships from clients to two different occurrences of MeasurementsData:

                                MeasurementsData|Date----------Clients-------<MeasurementsData

                                Clients::_pkClientID = MeasurementData::_fkClientID
                                     
                                     Clients::_pkClientID = MeasurementData|Date::_fkClientID AND
                                     Clients::gMDate = MeasurementsData}Date::DateField

                                gMDate would be a field with global storage in my example, (but it does not have to be global).

                                Your measurements fields on the tab would be selected from MeasurementsData|Date.

                                The following script would update gMDate with the next measurement date from MeasurementsData:

                                IF [ $$Mnumber < Count ( MeasurementsData::_fkClientID ) ]
                                         Set Variable [$$Mnumber ; Value:  $$Mnumber + 1 ]
                                         Set FIeld [ Clients::gMDate ; GetNthRecord ( MeasurementsData::DateField ; $$Mnumber ) ]
                                     End If

                                A button in your portal row can be set up to perform this script:

                                Set Field [Clients::gMDate ; MeasurementsData::DateFIeld ]
                                     Set Variable [$$Mnumber ; Value: Get ( ActivePortalRowNumber ) ]-->keeps date set of controls in sync

                                     1.  I'd need to know the context in which this script is performed.

                                In my LayoutClients within the Calories & Measurements tab I have LEFT and RIGHT arrows that I want to scroll through dates, BodyAgeDate, within the MeasurementData and/or MeasurementData2 table(s)  The script works when I want to go to past dates but not move to any date forward.

                                     2.  On what table occurrence is the layout based? (What layout is current when this script is performed?)

                                It is on LayoutClients

                                     3.  Why do you use the variable $$Mnumber here?

                                This is what you wrote out for me
                                      
                                     4.  What value does $$Mnumber have before these script steps are executed?
                                Same answer as above
                                      
                                Here are pics of the setup
                                • 13. Re: Cannot figure out script for layout tabs for date ranges and portals...
                                  philmodjunk

                                       Apologies for not recognizing my own suggestion! blush

                                       Am I correct that you now need to move through the records in the opposite direction to implement a script for the other arrow button?

                                       If that is what you want:

                                  IF [ $$Mnumber > 0 ]
                                      Set Variable [$$Mnumber ; Value:  $$Mnumber - 1 ]
                                      Set FIeld [ Clients::gMDate ; GetNthRecord ( MeasurementsData::DateField ; $$Mnumber ) ]
                                  End If

                                  • 14. Re: Cannot figure out script for layout tabs for date ranges and portals...
                                    danlee

                                         That worked!!!  Thank you!