Ljr0429 Posted March 23, 2014 Posted March 23, 2014 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
doughemi Posted March 23, 2014 Posted March 23, 2014 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]
Ljr0429 Posted March 23, 2014 Author Posted March 23, 2014 Thx I will give this a try and let you know how it turns out.....thx again
eos Posted March 23, 2014 Posted March 23, 2014 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 …
Ljr0429 Posted March 23, 2014 Author Posted March 23, 2014 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
eos Posted March 23, 2014 Posted March 23, 2014 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.
Ljr0429 Posted March 23, 2014 Author Posted March 23, 2014 thankyou i will give this a go, i really appreciate you taking the time and explaining this to me.....thx again
doughemi Posted March 24, 2014 Posted March 24, 2014 why declare a variable you never use? Well….Ummm….Errr……Uhhhh…..it seemed like a good idea at the time.
Lee Smith Posted March 24, 2014 Posted March 24, 2014 otherwise there'd be a bunch of records orphaned directly after birth … ROTFLMAO Thanks for my daily laugh.
eos Posted March 24, 2014 Posted March 24, 2014 Well….Ummm….Errr……Uhhhh…..it seemed like a good idea at the time. Don't I know that feeling …
eos Posted March 24, 2014 Posted March 24, 2014 Thanks for my daily laugh. As always, glad to be of service.
Rick Whitelaw Posted March 24, 2014 Posted March 24, 2014 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.
bruceR Posted March 24, 2014 Posted March 24, 2014 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.
LaRetta Posted March 24, 2014 Posted March 24, 2014 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. :-) 1
Recommended Posts
This topic is 3896 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now