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.
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?
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
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.
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)
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.
1 of 1 people found this helpful
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
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.
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.