locked
Setting todays date in a field on an entity RRS feed

  • Question

  • I am trying to set todays date in a date only field if the date is null or undefined. Getting an error: unable to get property 'setValue' of undefined or null reference. The value should be todays date. Any guidance would be appreciated.

    function setDateRequested()
    {
    var dateRequested = Xrm.Page.getAttribute('nhs_salesmaterialrequest').getValue();
    if (dateRequested == null || dateRequested == 'undefined' || dateRequested == '')
    {
    //var currentDate = new Date();
    //dateRequested.setValue(currentDate);
    dateRequested.setValue(Date.now());
    }
    }

    Thursday, August 17, 2017 7:59 PM

All replies

  • Hello Jennifer,

    Try following:

    function setDateRequested() {
    	var dateRequested = Xrm.Page.getAttribute('nhs_salesmaterialrequest').getValue();
    
    	if (dateRequested == null) {
    		Xrm.Page.getAttribute('nhs_salesmaterialrequest').setValue(new Date());
    	}
    }



    Dynamics CRM/Business Solutions MVP
    Read My blog

    Thursday, August 17, 2017 8:44 PM
    Moderator
  • This does not work. I get the error: This control only accepts strings or null as an input.

    Sorry about that must have hit save to soon.

    • Edited by JenniferNHS Thursday, August 17, 2017 9:15 PM
    Thursday, August 17, 2017 9:13 PM
  • What error do you get?

    Dynamics CRM/Business Solutions MVP
    Read My blog

    Thursday, August 17, 2017 9:14 PM
    Moderator