March 23, 201411 yr I am creating a timesheet db for work. I have a start date field and an end date field I would like to create a script that when start date and end date are entered portal rows will populate the dates from the start to end date. I can do this setting fields I am a beginning to scripting any help would be appreciated ......Thx Ljr
March 23, 201411 yr Try: Set Variable[$startDate; StartDateField] Set Variable[$theDate; $startDate] Set Variable[$endDate; EndDateField] Freeze Window Go to Layout ["SomeLayout"; YourPortalTO] # this could be any layout based on the TO that the portal relationship points to. Loop New Record/Request Set Field[DateField; $theDate] Set Variable[$theDate; $theDate + 1] Exit Loop If[ $theDate > $endDate] End Loop Go to Layout[Original Layout]
March 23, 201411 yr Author Thx I will give this a try and let you know how it turns out.....thx again
March 23, 201411 yr Hey Doug, why declare a variable you never use? Set Variable[$startDate; StartDateField] Set Variable[$theDate; $startDate] Set Variable[$endDate; EndDateField] Freeze Window Go to Layout ["SomeLayout"; YourPortalTO] # this could be any layout based on the TO that the portal relationship points to. Loop New Record/Request Set Field[DateField; $theDate $startDate + $i ] Set Variable[$i ; $theDate $i + 1] Exit Loop If[ $theDate $startDate + $i > $endDate] End Loop Go to Layout[Original Layout] <CODE> doesn't support strike-through …
March 23, 201411 yr Author Tried this script all that it is doing is adding the end date into the first first portal row, creating a new record and dumping the data
March 23, 201411 yr Tried this script all that it is doing is adding the end date into the first first portal row, creating a new record and dumping the data This script is not supposed to use a portal; it's supposed to go to a layout of the table occurrence the portal points at, create new records, then return. … but we've forgotten to tell you that you should carry a primary key with you make those records related to whatever record you're on in the current layout; otherwise there'd be a bunch of records orphaned directly after birth … OK, you don't need to worry about that if you use a portal. Make sure the relationship of the portal allows creation of related records, give your portal an object name (Inspector palette, Position tab) and try … Set Variable [ $begin; LayoutTO::StartDateField ] Set Variable [ $end; LayoutTO::EndDateField] Set Variable ( $existing ; List ( PortalTO::DateField ) ] Freeze Window Go to Object [ yourPortalName ] Go To Portal Row [ last ] Loop Set Variable [ $cur ; $begin + $i ] If [ IsEmpty ( FilterValues ( $existing ; $cur ) ) ] Set Field [ PortalTO::DateField ; $cur ] Go to Portal Row [ next ] End If Set Variable[ $i ; $i + 1] Exit Loop If [ $begin + $i > $end] End Loop Commit Record/Request This version with a bit of duplicate-preventing code thrown in.
March 23, 201411 yr Author thankyou i will give this a go, i really appreciate you taking the time and explaining this to me.....thx again
March 24, 201411 yr why declare a variable you never use? Well….Ummm….Errr……Uhhhh…..it seemed like a good idea at the time.
March 24, 201411 yr otherwise there'd be a bunch of records orphaned directly after birth … ROTFLMAO Thanks for my daily laugh.
March 24, 201411 yr Well….Ummm….Errr……Uhhhh…..it seemed like a good idea at the time. Don't I know that feeling …
March 24, 201411 yr This script is not supposed to use a portal; it's supposed to go to a layout of the table occurrence the portal points at, create new records, then return. … but we've forgotten to tell you that you should carry a primary key with you make those records related to whatever record you're on in the current layout; otherwise there'd be a bunch of records orphaned directly after birth … OK, you don't need to worry about that if you use a portal. Make sure the relationship of the portal allows creation of related records, give your portal an object name (Inspector palette, Position tab) and try … Set Variable [ $begin; LayoutTO::StartDateField ] Set Variable [ $end; LayoutTO::EndDateField] Set Variable ( $existing ; List ( PortalTO::DateField ) ] Freeze Window Go to Object [ yourPortalName ] Go To Portal Row [ last ] Loop Set Variable [ $cur ; $begin + $i ] If [ IsEmpty ( FilterValues ( $existing ; $cur ) ) ] Set Field [ PortalTO::DateField ; $cur ] Go to Portal Row [ next ] End If Set Variable[ $i ; $i + 1] Exit Loop If [ $begin + $i > $end] End Loop Commit Record/Request This version with a bit of duplicate-preventing code thrown in. Eos, where is the variable "$i" originally declared? Rick.
March 24, 201411 yr It is not originally declared. That's all the rage. Since it is not declared, nothing +1 results in 1 the first time through. I prefer to explicitly declare it, which can be helpful when using debugger to troubleshoot a script.
March 24, 201411 yr Just as an added caution ... whenever possible, it is better to go to the other layout behind a Freeze Window[] to create your records rather than counting on the portal. Sometime in the future, you may decide to replace the portal or remove it completely which will break your script. You can put developer notes off screen to the right pointing out any hidden elements and this would be good to mention there. :-)
Create an account or sign in to comment