locked
Set Value of date field to today when another Option Set field changes. RRS feed

  • Question

  • I am trying to set today's date in a date field when statuscode is changed.  I keep getting "unable to get property "setValue" of undefined or null reference."  Here is my code:

    function ClosedbyMkt_onchange()
    {
    var LeadStatus = Xrm.Page.getAttribute("statuscode").getValue();
    var SchedForwardDate = Xrm.Page.data.entity.attributes.get("new_schedforwarddate");
    var today = new Date();
    var SFD = new Date(today.setDate(today.getDate()));
    if(LeadStatus == 957200002)
       { 
          SchedForwardDate.setValue(SFD);
      }
    }

    I've tried every piece of code found on the various blogs etc. and still no luck.  Any ideas are appreciated.


    Ken Compter

    Friday, November 15, 2013 7:41 PM

All replies

  • Hi Ken,

    Please make sure new_schedforwarddate field is on the entity form.

    Thanks,

    Swaroop

    Friday, November 15, 2013 10:20 PM
  • Thank you for the reply.  the field is on the form.

    Ken Compter

    Saturday, November 16, 2013 3:17 PM
  • Try like as below :

    function ClosedbyMkt_onchange() {
        var LeadStatus = Xrm.Page.getAttribute("statuscode").getValue();
        var SchedForwardDate = Xrm.Page.data.entity.attributes.get("new_schedforwarddate");
        var today = new Date();
        if (LeadStatus == 957200002) {
            SchedForwardDate.setValue(today);
        }
    }


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !

    Saturday, November 16, 2013 3:37 PM
  • Hi,

    Try below code.

    Xrm.Page.getAttribute("new_schedforwarddate").setValue(new Date());

    HTH!

    Thanks!

    Sunday, November 17, 2013 9:16 AM
  • Still getting    <Message>Unable to get property 'setValue' of undefined or null reference</Message>

    Ken Compter

    Sunday, November 17, 2013 3:06 PM
  • Check the spelling of the attribute new_schedforwarddate.
    Sunday, November 17, 2013 3:21 PM