locked
date format RRS feed

  • Pergunta

  • Hi

    I have a javascript that supposed to return a date, I change sistem settings of CRM with M/d/yyyy H:mm, then i format the date of the value in the javascript, but i get the following error, properrty or method not supported.

     

    formatDate.endDate ("M/d/yyyy H:mm");
    crmForm.new_caseresponsetime.value=endDate;

     

    Thks in advance

    segunda-feira, 21 de abril de 2008 07:56

Respostas

Todas as Respostas

  • Cosminc,

     

    Have you write the formatDate function?

    You can get the date by using:

     

    Code Snippet

    var now = new Date();
    var M = now.getMonth();
    var d = now.getDate();
    var y = now.getYear();
    var H = now.getHours();
    var m = now.getMinutes();

    alert(M+1+"/"+d+"/"+y + " " +H+":"+m);

     

     

    Regards,

    Jim

     

    segunda-feira, 21 de abril de 2008 10:43
    Moderador
  • Hi

    Thks for the answer, but that doesn't help me too much,I can't write another function because that mean that i have an onSave function and in this function i write another function dateformat??

     

    The problem is  that, i have this script, at the end of the script i put the endDate value in new_casereponsetime field, but the endDate value looks like (Tue 22 april etc), and Microsoft CRM 4 date looks like M/d/yyyy H:mm.What I don't know is how to format endDate to be the same as microsoft crm 4.

     

    Thks for future reply Smile

    --------------------------------------------------------------------------------------------------------------------------SCRIPT---------------------------------------

    if (crmForm.prioritycode.value == 3 && crmForm.contractservicelevelcode.value == 2)
         {
    //This is the time the customer creates a support ticket
       var currentDate = new Date()

       
       //The number of hours you need to add
       var hoursToAdd = 8;
       
       //Working hours
       var workStartHour = 8;
       var workEndHour = 17;
       
       //The number of hours you're working each day
       var hoursPerDay = workEndHour - workStartHour;
       
       var startDate;
       
       //If the support ticket is created inside of your working hours, this is the start date
       if ((currentDate.getHours() > workStartHour) && (currentDate.getHours() < workEndHour)) {
        startDate = currentDate;
       }
       
       //Otherwise use the next day
       else {
        startDate = new Date(
         currentDate.getYear(),
         currentDate.getMonth(),
         currentDate.getDate()+1,
         workStartHour,
         0,
         0);
       }
       
       //If the start date is a Saturday, add two days (next Monday)
       if (startDate.getDay() == 6) {
        startDate.setDate(startDate.getDate() + 2);
       }
       
       //If it's a Sunday, add one day (next Monday)
       else if (startDate.getDay() === 0) {
        startDate.setDate(startDate.getDate() + 1);
       }
       
       //Show the actual start date
       //alert("Start Date = " + startDate);
       
       //Not let's calculate the end date
       var endDate = startDate;
       
       //If there are more hours to add than you're working each day, we add days instead of hours
       while (hoursToAdd >= hoursPerDay) {
       
        //Add one day to the end date
        endDate.setDate(endDate.getDate() + 1);
       
        //If the end date now is a Saturday, add two days (next Monday). It cannot be a Sunday, as
        //the previous code ensures that endDate initially is set to a date between Monday and Friday.
        if (endDate.getDay() == 6) {
         endDate.setDate(endDate.getDate() + 2);
        }
       
        //Subtract the number of hours for the day added
        hoursToAdd -= hoursPerDay;
       }
       
       //Add the remaining hours
       endDate.setHours(endDate.getHours() + hoursToAdd);
       
       //If the time is outside of the working hours, we again need to adjust the time
       if (endDate.getHours() >= workEndHour) {
        //Add (24 - hours per day) to the end date, so it points into the working hours of
        //the next day.
        endDate.setHours(endDate.getHours() + 24 - hoursPerDay);
       
        //Final test: if the end date is a Saturday, point it to the next Monday
        if (endDate.getDay() == 6) {
         endDate.setDate(endDate.getDate() + 2);
    //endDate.dateformat ("M/d/yyyy h:mm tt");

        }
       }
       
       //Show the result
                                                                   // formatDate.endDate ("M/d/yyyy H:mm");
                                                                    new_caseresponsetime.value=endDate;
       alert (new_caseresponsetime.value);
                                                                                                                                                                                              
       //return endDate;
      }

     

    --------------------------------------------------------------------------------------------------------------------------SCRIPT---------------------------------------

    segunda-feira, 21 de abril de 2008 12:15
  • Cosmioc,

     

    Don't use .value, try .DataValue, you can just use .DataValue to set the datatime in CRM:

    Code Snippet
    crmForm.all.new_caseresponsetime.DataValue = new Date(); // you can change it to your custom time

     

     

    See different between .value and .DataValue, see my blog: http://jianwang.blogspot.com/2008/04/how-to-format-number-fieldinteger.html

     

    Hope it helps!

     

    Cheers,

    Jim

    segunda-feira, 21 de abril de 2008 20:03
    Moderador
  • Thank you i did it Smile

    quarta-feira, 23 de abril de 2008 13:05