locked
auto filling in date on crm form RRS feed

  • Question

  • I want to save the date and time 12:00am
    is this possible on the form I've put this code onsave in the form but I keep getting an error

    var time= new Date();
    var month = time.getMonth()+1;
    var day = time.getDate();
    var year = time.getFullYear();

    crmForm.all.new_sendoutdate.DataValue = month+ "/"  + day + "/"  + year;

    I noticed there are two dropdowns on the form so I'm not sure if this is possible.
    new_sendoutdate is a datetime attribute

    Wednesday, November 11, 2009 9:40 PM

Answers

  • // Returns date in "m/d/yyyy" format.
            Date_Format = 
                function (dtDate)
                {
                    var iMonth = dtDate.getMonth() + 1;
                    var iDay = dtDate.getDate();
                    var iYear = dtDate.getFullYear();
                    
                    return iMonth + "/" + iDay + "/" + iYear;
                }
    
    
    
    
    var currenttime= new Date();
    
    crmForm.all.new_sendoutdate.DataValue = Date_Format(currenttime)
    


    try puting above code and this see if it works...

    I guess the reason you were getting error....becuase of variable "time"..


     


    Wednesday, November 11, 2009 10:12 PM
    Answerer

All replies

  • got it. need to convert back to date. thought since it was a textbox should just take a string. code solution follows

    if(crmForm.FormType = 1)
    {
    var time= new Date();
    var month = time.getMonth()+1;
    var day = time.getDate();
    var year = time.getFullYear();
    var backtodate =  new Date(year+ "/"  + month+ "/"  + day);
    crmForm.all.new_sendoutdate.DataValue = backtodate;
    }

    this sets the day to today and time to midnight.
    Wednesday, November 11, 2009 10:05 PM
  • // Returns date in "m/d/yyyy" format.
            Date_Format = 
                function (dtDate)
                {
                    var iMonth = dtDate.getMonth() + 1;
                    var iDay = dtDate.getDate();
                    var iYear = dtDate.getFullYear();
                    
                    return iMonth + "/" + iDay + "/" + iYear;
                }
    
    
    
    
    var currenttime= new Date();
    
    crmForm.all.new_sendoutdate.DataValue = Date_Format(currenttime)
    


    try puting above code and this see if it works...

    I guess the reason you were getting error....becuase of variable "time"..


     


    Wednesday, November 11, 2009 10:12 PM
    Answerer