Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 3896 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

Posted

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]
Posted

Hey Doug,

 

why declare a variable you never use?  :grad:  :laugh:

 

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 …
Posted

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

Posted

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 …  :cry:

 

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.
Posted

 

why declare a variable you never use?  :grad:  :laugh:

 

Well….Ummm….Errr……Uhhhh…..it seemed like a good idea at the time. :Whistle:

Posted

otherwise there'd be a bunch of records orphaned directly after birth …  :cry:

 

ROTFLMAO

 

Thanks for my daily laugh.

Posted

Well….Ummm….Errr……Uhhhh…..it seemed like a good idea at the time. :Whistle:

 

Don't I know that feeling …  :ermm:

Posted

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 …  :cry:

 

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.

Posted

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.

Posted

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.  :-)

  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.