locked
Lock the date and time fields on a follow-up By Field 2 hours after it is created.once we opened after 2 hours it should be in disabled state.and if we opened within 2 hours we can able to see out date our date and time RRS feed

  • Question

  • time fields on a follow-up By Field 2 hours after it is created.once we opened after 2 hours it should be in disabled state.and if we opened within 2 hours we can able to see out date our date and time.

    Here is My code:

    But I cannot able to disable my field

    function disableControl()
    {
    debugger;
    var date = new Date();
    date.setHours(date.getHours());
    //alert(date);
    var d1 = new Date();
    d1.setHours(d1.getHours()+2);
    //alert(d1);

    if(date==d1)
    {
    Xrm.Page.ui.controls.get("fmc_followupby").getDisabled(true);
    }

    }

    Can u plz help me out

    Thanks

    Friday, February 14, 2014 1:12 PM

All replies

  • Hello,

    Where are you getting date from crm follow-up field ?? try something like below

    function disableControl()
    {
    //get date from ms crm

    var date = new Date(Xrm.Page.getAttribute('followupdate').getValue());
    varr d1 = new Date();
    date.setHours(date.getHours()+2);

    if(date<d1)
    {
    Xrm.Page.ui.controls.get("fmc_followupby").getDisabled(true);
    }

    }


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    Friday, February 14, 2014 1:55 PM
    Moderator
  • Hi,

    Here is my form below the subject Follow_Up By field is there with date and time.Once I selected date  and time in that calendar,  when I open the form after 2 hours it should be  in disabled  format .

    I Tried with the code what u have given but error is getting unable to getproperty of 'getValue' of undefined or null reference.

    function disablecontrol()
     {
     //get date from ms crm

    var date = new Date(Xrm.Page.getAttribute('followupdate').getValue());
     var d1 = new Date();
     date.setHours(date.getHours()+2);


    if(date<d1)
     {
     Xrm.Page.ui.controls.get("fmc_followupby").getDisabled(true);
     }

    }

    Can u plz help me out

    Thanks

    Sunday, February 16, 2014 7:11 AM
  • Hi,


    Insure that the field value you are getting it must exists in form weather it may be enable of disable.

    Check weather the field contains any value or not.

    And another thing to disabled a control you should have write 

    Xrm.Page.ui.controls.get("fmc_followupby").setDisabled(true);

    not Xrm.Page.ui.controls.get("fmc_followupby").getDisabled(true);

    function disablecontrol() {
        //get date from ms crm
        if (Xrm.Page.getAttribute('followupdate').getValue() == null) return;//or else show some message to user
        var date = new Date(Xrm.Page.getAttribute('followupdate').getValue());
        var d1 = new Date();
        date.setHours(date.getHours() + 2);
    
        if (date < d1) {
            Xrm.Page.ui.controls.get("fmc_followupby").setDisabled(true);
        }
    
    }

    Regards,

    Priya

    • Proposed as answer by PriyaSwain Thursday, February 20, 2014 11:52 AM
    Thursday, February 20, 2014 11:52 AM