Current Time

How can I prime the field on the form with current time ?

wow, nobody ? there should be the way ?
I’m surprised SC does provide this functionality for the DATE but not for the TIME

I think you can do it in onload event, use function php for asign the time to your field. and use macro for verify if is a new record.
if (sc_btn_new)
{
asign the time to your field;…
}

thanks but I still do not know how to do it. I can handle SC macros, but I’m not a PHP programmer

ONLOAD RECORD
if (sc_btn_new)
{
{Mytime} = [SIZE=15px]date(“h:i:s”);[/SIZE]
}

thanks - alvagar

I use another software (for desktop dev) where there are 4 modes for the form. Based on those modes developer can take different actions. This works lika a charm as you can always test what mode is active. For example 1=Inseret 2=Eidt 3=Delete 4=Select
I wish it would work the same in SC as it makes very easy to perform actions based on the state 1-4

Ok, so can I do this conditionally ?
If user adds New Record I want to populate field with current time, but when the user Edits a record I want the data from the database to show up ?
Another words is there any indicator if the form is opened in INSERT or EDIT mode ?

A new ID is not assigned until the new data is inserted, so you can do:


if ( {ID} < 1 ) {
    {Mytime} = [SIZE=15px]date("h:i:s");[/SIZE]
}

You can also check for a value in the time field, but that would populate on Edit. If the time is a required field, then it has to be present to insert. If that is the case, you can just check to see if there is a value, then add one if not.


if ( !{Mytime} ) {
    {Mytime} = [SIZE=15px]date("h:i:s");[/SIZE]
}

[edit] Forgot about the Button macros. You can tell the state by what button was clicked to get to your form. Check out Scriptcase Macros -> Buttons.

Yes I understand your example, thanks.
My additional question is how to figure out if the form is open for Inserting or for Editing ?

As travlr posted, by scriptcase macro’s Look at the docs at:
[TABLE=“class: macros_desc_main_table, cellpadding: 0, cellspacing: 0”]
[TR]
[TD=“class: macros_tit”]sc_btn_insert[/TD]
[/TR]
[TR]
[TD] [TABLE=“class: macros_desc_table”]
[TR]
[TD] Available when the “Add” button is clicked. Can be tested and used inside the ScriptCase events, allowing especific programmation in run time.

					[B]Ex. 1:[/B]
					if (sc_btn_insert)
					{
					sc_message("Record inserted successfully");
					}
					[/TD]
				[/TR]
			 			[/TABLE]
		   			[B]Macro Scope[/B]
		[TABLE="class: macros_desc_scope_table, cellpadding: 0, cellspacing: 0"]
			 					[TR]
					[TD]Form application[/TD]
				[/TR]
				[TR]
					[TD="width: 120px, bgcolor: #f7f4f4"]onValidate
					onValidateFailure
					onValidateSuccess[/TD]
				[/TR]
			 			[/TABLE]
		[/TD]
	[/TR]
 [/TABLE]

Below the docs you will find sample for the other states.

yes, I understand the part about assigning the time.
Albert - I’m not getting your suggestions, but perhaps because I’m coming from the desktop programing, where certain things are a bit different.
When user clicks NEW (with the intention of adding a New Record) then the grid App (linked to the form) and opens a blank form causing adding a new record - RIGHT ?
When user clicks PENCIL icon then the same form opens but instead the form reads the record into the form FIRST - RIGHT ?

so what/how it is determined to load existing data into the form OR open empty form ?
there must be some variable that allows to make that decission

ARTHUR

The form opens normally in insert mode if there are no records in the grid. The form opens in read/edit mode when there are records in the grid. Then you see the new button as Albert said…
But I havent tested this in detail, Albert’s way is the easy solution.