Set CRM Date Field to Empty

I have a check box and a date field on the form. The requirement is to display the System Date in the date field when the check box is checked by the user and to clear the date field when the check box is unchecked by the user. Although the user has unchecked the check box and saved the form it displays the previously saved date by the user. I used the following code to save it.

Following code will solve the problem and will set it to Empty when it saved.

      //get the value of Reviewed by Manager checkbox
    var ReviewedManager = crmForm.all.cpms_reviewedbymanager.DataValue;

    //if Reviewed by Manager chekbox is checked
    if (ReviewedManager == true)
    {
        //set the Date Reviewed by  to system date
        crmForm.all.cpms_datereviewedbymanager.Disabled = false;
        crmForm.all.cpms_datereviewedbymanager.DataValue = new Date();
    }
    else
    {
        crmForm.all.cpms_datereviewedbymanager.DataValue = null;
        crmForm.all.cpms_datereviewedbymanager.ForceSubmit = true;
        crmForm.all.cpms_datereviewedbymanager.Disabled = true;
    }

Advertisement

Author: Indika Abayarathne

MSc in IT [University of Colombo] Solutions Architect | Consultant Technologies: Power Platform | Dynamics CE | Azure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: