locked
Setting default time in a Task RRS feed

  • Question

  • I have found different scripts to change the time field when a date is selected however they have not been for tasks but for meeting.

    I know my variable is scheduledend as this controls the due date field in a task.

    I am unable to find out how to change the script (or make one however) to call the variable here and set the time once the date is selected.

    I found a few things that were very close but not based on the new CRM 2011 SDK therefor commands were not working.

    The closest thing I could find was to change a meeting

    Is there a way I can modify this for the Tasks form and the variable scheduledend ?

    var att = Xrm.Page.getAttribute('scheduledstart');
    var curDate = att.getValue
    curDate.setHours(9,0,0);
    att.setValue(curDate);
    

    Thanks for all of your help.

    Thursday, August 18, 2011 8:22 PM

Answers

  • I though that you are defining a namespace in JScript and then adding funciton into it, you need to use it liek this:

    function SetDefaultValue() {

    var FORM_TYPE_CREATE = 1;
    var FORM_TYPE_UPDATE = 2;
    var FORM_TYPE_READ_ONLY = 3;
    var FORM_TYPE_DISABLED = 4;
    var FORM_TYPE_QUICK_CREATE = 5;
    var FORM_TYPE_BULK_EDIT = 6;

    var formType = Xrm.Page.ui.getFormType();
    if (formType == FORM_TYPE_CREATE) {

    var att = Xrm.Page.getAttribute('scheduledend');
    var curDate = att.getValue();
    curDate.setHours(9,0,0);
    att.setValue(curDate);

    }

    }

    and in FormOnload event use SetDefaultValue as funciton name


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, August 19, 2011 2:43 PM
  • Gave it a run and get the following when opening a new task

     

    Field:window

    Event:onload

    Error:'null' is null or not an object

     

    Most likely since the value is not set when opening a new task correct?

     

    EDIT : Fixed it by setting it from Form Onload to Due OnChange

     

    Thanks!!!


    • Marked as answer by GeneralPatton Friday, August 19, 2011 2:53 PM
    Friday, August 19, 2011 2:51 PM

All replies

  • HI,

    Yes you can modify and use the code bekow on FormOnload event:

    // If form mode is in Create mode

    if( Xrm.Page.ui.getFormType() == 1)
    

    {

    var att = Xrm.Page.getAttribute('scheduledend');
    var curDate = att.getValue();
    curDate.setHours(9,0,0);
    att.setValue(curDate);


    }

     


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, August 19, 2011 1:36 AM
  • I am receiving the following error from the string to check on the form type :

       <Message>'Xrm.Page.ui' is null or not an object</Message>

     

    So I did some looking and rewrote the code as follows below :

    getFormType: function () {
    
     var FORM_TYPE_CREATE = 1;
     var FORM_TYPE_UPDATE = 2;
     var FORM_TYPE_READ_ONLY = 3;
     var FORM_TYPE_DISABLED = 4;
     var FORM_TYPE_QUICK_CREATE = 5;
     var FORM_TYPE_BULK_EDIT = 6;
    
     var formType = Xrm.Page.ui.getFormType();
     if (formType == FORM_TYPE_CREATE) {
    
    var att = Xrm.Page.getAttribute('scheduledend');
    var curDate = att.getValue();
    curDate.setHours(9,0,0);
    att.setValue(curDate);}
    
    
    }
    
    I do not receive any errors however the the default time when the date is selected is still set to 12:00AM
    Is this because im looking for a current Date set onLoad but there is none until one is selected?

    Friday, August 19, 2011 1:58 PM
  • Hi,

    The above script will be only run on New Form, try run code with new form condition: 

    getFormType: function () {

    var att = Xrm.Page.getAttribute('scheduledend');
    var curDate = att.getValue();
    curDate.setHours(9,0,0);
    att.setValue(curDate);

    //will alert system date

    alert(curDate);

    }

     


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, August 19, 2011 2:31 PM
  • If I run that code I get the following error when making a new task :

     

    There was an error with this field's customized event.

     

    Field : window

    Event : onload

    Error: Object doesn't support this property or method

     

    I did some looking and task.scheduledend might need to be used instead

    http://msdn.microsoft.com/en-us/library/bb959217.aspx

     

    Can I use that to set a default time? Or should I be using the OnChange of the Due field instead of OnLoad of the form?


    If I run the command on change wouldnt that allow the user to specify the date then overwrite the system default time with the one I specify?
    Friday, August 19, 2011 2:39 PM
  • I though that you are defining a namespace in JScript and then adding funciton into it, you need to use it liek this:

    function SetDefaultValue() {

    var FORM_TYPE_CREATE = 1;
    var FORM_TYPE_UPDATE = 2;
    var FORM_TYPE_READ_ONLY = 3;
    var FORM_TYPE_DISABLED = 4;
    var FORM_TYPE_QUICK_CREATE = 5;
    var FORM_TYPE_BULK_EDIT = 6;

    var formType = Xrm.Page.ui.getFormType();
    if (formType == FORM_TYPE_CREATE) {

    var att = Xrm.Page.getAttribute('scheduledend');
    var curDate = att.getValue();
    curDate.setHours(9,0,0);
    att.setValue(curDate);

    }

    }

    and in FormOnload event use SetDefaultValue as funciton name


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, August 19, 2011 2:43 PM
  • Gave it a run and get the following when opening a new task

     

    Field:window

    Event:onload

    Error:'null' is null or not an object

     

    Most likely since the value is not set when opening a new task correct?

     

    EDIT : Fixed it by setting it from Form Onload to Due OnChange

     

    Thanks!!!


    • Marked as answer by GeneralPatton Friday, August 19, 2011 2:53 PM
    Friday, August 19, 2011 2:51 PM
  • I tried your code above:

    getFormType: function () {

     var FORM_TYPE_CREATE = 1;
     var FORM_TYPE_UPDATE = 2;
     var FORM_TYPE_READ_ONLY = 3;
     var FORM_TYPE_DISABLED = 4;
     var FORM_TYPE_QUICK_CREATE = 5;
     var FORM_TYPE_BULK_EDIT = 6;

     var formType = Xrm.Page.ui.getFormType();
     if (formType == FORM_TYPE_CREATE) {

    var att = Xrm.Page.getAttribute('task.scheduledend');
    var curDate = att.getValue();
    curDate.setHours(9,0,0);
    att.setValue(curDate);}

    }

    But I get this error:

    "THere was an error with this field's customized event. 

    Field:  window

    Event: onload

    Error: The value of the property 'SetDefaultValue' is null or undefined, not a Function object."

    Why would I get this and how do I fix it?  I'm trying to have a new task automatically enter today's date as the due date with duration null.

    Please help.

    Tuesday, May 29, 2012 6:09 PM
  • This was fixed in a subsequent post just search down sorry.
    Tuesday, May 29, 2012 6:24 PM