8 Replies Latest reply on Jun 3, 2017 6:52 PM by billowen

    Insert From Last (Hotel) Visited

    billowen

      I have a Table called Accommodations that lists the hotels a tour is staying in entry fields include DayNumber & Nights (they are staying there).

       

      Using that and referencing the tour start date entered in the Group table, one can enter Day 1 first and the program will display the departure date and then by adding the number of nights, the check out date from that hotel. Example:

       

      Day Number (entry)Arrival Date (calculated)
      Check Out Date (calculated)Nights in Stay (entry)
      14/20/20184/22/20182
      34/22/20184/23/20181
      44/23/20184/27/20184

       

      I have been doing the math in my head: Day 1 + 2 (nights), okay manually enter 3 for the 2nd hotel's day number.

       

      FinallyI got courageous and tried the Insert From Last Visited script step and couldn't get it to do anything: it didn't build a new record in the Accommodations table (although I tried with and without New Record step too) and so didn't enter anything (the original day # or the calculation I specified DayNumber + Nights, either).

       

      Do you can see what I should be doing? Thanks!

        • 1. Re: Insert From Last (Hotel) Visited
          Jaymo

          Insert from Last Visited doesn't create a new record. It simply copies one field from the last visited record. The last visited record is not necessarily the last one visited. A record is visited when a field is selected. It's not clear to me but are you trying to create records for each night of the stay. Please clarify. Thanks.

          • 2. Re: Insert From Last (Hotel) Visited
            billowen

            Hi Jaymo,

            Thanks for a quick response.

             

            I am not trying to create a record for each night of the stay. Just a record for each hotel which could be 1 or more nights' stay.

             

            I tried it again with the New Record/Request step before Insert From Last Visited and it created a new Group ...blank except for the first Related Record in Accommodations with the same Day # as the last hotel record's Day Number.

             

            While I don't want a new Group, just a new Accommodation Record in the same Group, I thought that this is progress.

             

            So I tried doing the calculation Day Number + Nights ...and this time, I created a new Group (again, yuck) but the the related Accomodations record created there was Day Number 1 (sigh!) so the calculation is not referencing either the last field or the number of nights.

             

            I guess I need to first know how to Add a New RELATED Accommodations Record in the same Group table. Then I might be able to figure out how to add the nights ...maybe adding a pair of Insert From Last Visited steps -- one specifying the Day Number and the other specifying the Nights?

            • 3. Re: Insert From Last (Hotel) Visited
              billowen

              I realize that I don't have to have the script create a related record, just click into the blank Accommodations portal line and that creates the record and then have the script somehow do the math.

               

              But so far I seem to be throwing darts blindfolded with no response at all -- the new related record remains blank

              • 4. Re: Insert From Last (Hotel) Visited
                billowen

                I obviously don't even know how to work this discussion process as I've marked various things as correct but nothing I have done is correct so far.

                • 5. Re: Insert From Last (Hotel) Visited
                  erolst

                  You have a group that has stays. So far, so good.

                   

                  A group is one table, stays are related records.

                   

                  You need a script that analyzes the existing stays for that group and automatically adds a new, calculated arrival date and the day number within the entire trip.

                   

                  While there are better ways, let's do this using your existing portal; for this to work

                   

                  - you must give that portal an object name in the Inspector, say, "portal_stays" (in the Inspector, enter the name without the quotes)

                  - the underlying relationship must "Allow creation of related records" for the Stays table occurrence (which it already does if you manually added records in the portal)

                   

                  Script NewStayForGroup

                   

                  Set Variable [ $arrivalDate ; Max ( Stays::Check Out Date ) ]

                  Set Variable [ $dayNumber ; Max ( 1 ; $arrivalDate - Min ( Stays::Arrival Date ) ) ]

                  Go to Object [ "portal_stays" ]

                  Go to Portal Row [ last ]

                  Set Field [ Stays::Arrival Date ; $arrivalDate ]

                  Set Field [ Stays::DayNumber ; $dayNumber ]

                  Go to Field [ Stays::Nights in Stay ]

                   

                  This is the logic as I understand it from seeing your data.

                   

                  Note that this is an optimistic/non-defensive script, because it assumes that existing data is complete. Fine-tuning would start with considering what could be missing, and guard against that.

                   

                  Anyway, that may give you a start.

                  • 6. Re: Insert From Last (Hotel) Visited
                    philmodjunk

                    Define srTotalNightsInStay as a running total summary of your nights in stay field.

                     

                    This calculation can then be the definition for a calculation field used for your Day Number Field:

                     

                    srTotalNightsInStay - Nights In Stay + 1

                    1 of 1 people found this helpful
                    • 7. Re: Insert From Last (Hotel) Visited
                      billowen

                      Thanks philmodjunk! That was simple enough for me to make it work. I already had a nights summary but it was not Running so I added that and it's work well enough for me.

                      • 8. Re: Insert From Last (Hotel) Visited
                        billowen

                        Thanks erolst. I got stuck right away because I couldn't figure out what the Inspector was. But I do appreciate your laying out your recommendation.