Alpha DevCon 2018
Results 1 to 6 of 6

Thread: Default Date In Grid

  1. #1
    "Certified" Alphaholic Phil Rolf's Avatar
    Real Name
    Philip Rolf
    Join Date
    Apr 2000
    Location
    Kentucky
    Posts
    1,539

    Default Default Date In Grid

    I have a GRID that has a date field from a table. When ENTERING a record into the grid how can I get the date field of the table to default to todays date? I have date() in the default portion of the field rules and the date is NOT being inserted. Where am I going wrong?

  2. #2
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,786

    Exclamation Re: Default Date In Grid

    Hi Phil,

    The Field Rule Default has no effect on data-entry from a Grid; it won't fire your default value even after you press Submit. Calc Field Rules do work, so you might be able to issue an IF BLANK.... expression. You could also put this in the BeforeValidateNewRecords event:

    if DataSubmitted.MYDATE = null_value()
    DataSubmitted.MYDATE = date()
    end if

    But, on a Grid, none of that will make a value magically appear in a new record row before you press Submit, or have it pop in as you tab through the field.

    On a Dialog, the opposite is true, you can cause a default value to appear in any control.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  3. #3
    "Certified" Alphaholic Phil Rolf's Avatar
    Real Name
    Philip Rolf
    Join Date
    Apr 2000
    Location
    Kentucky
    Posts
    1,539

    Default Re: Default Date In Grid

    How you doing? Long time no speak with the webinar. One of these days I will remember and not be to busy. Thanks for the Security Breach email.

    Your code did not work. I even tried changing it to isblank and even changed the code to eliminate the IF and just use the DataSubmitted.MYDATE = date() and the date still did not get placed in the table. I tried the code in all the Events and nothing is working. This should not be that difficult. I may have to resort back to a dialog where I have a bit more control.

  4. #4
    "Certified" Alphaholic Rich Hartnett's Avatar
    Real Name
    Richard Hartnett
    Join Date
    Nov 2002
    Location
    Bowie, MD
    Posts
    1,447

    Default Re: Default Date In Grid

    If it helps any, I use a similar feature to automatically insert the current date and time into my table upon the user clicking the submit button by using the following code in the "Before Validate New Records" section:

    function BeforeValidateNewRecords as v (DataSubmitted as P, Args as p, PageVariables as p)
    with PageVariables
    DataSubmitted.DateRecordEntered=date()
    DataSubmitted.TimeRecordentered=time()
    end with
    end function

    Seems to work fine for me.
    Sergeant Richard Hartnett
    Hyattsville City Police Department
    Maryland

  5. #5
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,786

    Default Re: Default Date In Grid

    For the event to work, the field cannot be a Label. It could be a TextBox or Hidden (but not Hide Row) for example. For it to work the field has to be in the grid somewhere. And, I know you know this, MYDATE has to be your own field name. If you need the users to see the date, but not change it, and still have the default, create a Calculated field in the grid that shows data(). Use that as the visual, along with the real field as a Hidden.

    My example BeforeValidateNewRecords looks like this:

    Code:
    function BeforeValidateNewRecords as v (DataSubmitted as P, Args as p, PageVariables as p)
    with PageVariables
    if DataSubmitted.lastlogin = null_value()
    	DataSubmitted.lastlogin = date()
    end if
    end with
    end function
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  6. #6
    Member
    Real Name
    Otto Gustafson
    Join Date
    Apr 2006
    Posts
    26

    Default Re: Default Date In Grid

    As usual if I search long & hard enough I find an answer to my problem in a Steve Wood post; thanks.
    I now know why I can't get today's date to appear in a Detail View date field on an existing record when the field 'gets focus' (not a new record using the insert operation).

    It seemed that it should work. The user/operator, after tabbing into the field, can populate the field with the date picker by simply selecting the 'today' button in the picker. BUT they just want Today's date to appear for 99% of the time.
    It has been frustrating to not be able to simulate the same result for the user without them having to perform the extra keystrokes/mouse clicks. After all if the DatePicker has code to fill in the field object, why can't I figure out the code to do the same and include it in an instream java code.

    Also there is a need to have the date appear before they submit the update (they want the confidence of seeing the date before they save), ie., caninsert & canupdate work can help, but do not solve the user's request.

    Has anyone implemented this feature, ie., when tabbing into a date field on a Detail View, today's date appears (without using the date picker) before the user commits to save the updated record?

    Thank you,
    Otto Gustafson
    Last edited by otto17; 05-29-2013 at 12:56 AM.

Similar Threads

  1. Default Value based on another field value in Dropdown within GRID
    By den1s in forum Application Server Version 8
    Replies: 0
    Last Post: 06-21-2007, 05:23 AM
  2. Default date value
    By Ales in forum Alpha Five Version 8
    Replies: 11
    Last Post: 05-18-2007, 03:53 PM
  3. Default Values on Grid
    By gregz in forum Web Application Server v7
    Replies: 10
    Last Post: 02-03-2006, 01:52 PM
  4. Default Grid Field Value
    By MinamiT in forum Web Application Server v7
    Replies: 3
    Last Post: 01-09-2006, 10:56 PM
  5. Default Date
    By Phil Rolf in forum Web Application Server v6
    Replies: 1
    Last Post: 11-21-2004, 06:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •