web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Javascript Set Default Date in 90 days

(0) ShareShare
ReportReport
Posted on by 1,540

I have 4 fields that I'd like to set a default date for so decided to use javascript rather than 4 business rules.

My javascript is giving the error "nowDate.getDate is not a function at SetDefaultDates"

My javascript:

function SetDefaultDates() {
    console.log("Set Default Dates");
    console.log("End Dates: now + 90 days");
    var daysToAdd = 90;
    var nowDate = Date.now();
    console.log(nowDate);
    var endDate = new Date().setDate(nowDate.getDate() + daysToAdd);
    console.log(endDate);
    if (Xrm.Page.getAttribute("cld_billingstartdate").getValue() == null)
        Xrm.Page.getAttribute("cld_billingstartdate").setValue(Date.now());
    if (Xrm.Page.getAttribute("cld_billingenddate").getValue() == null)
        Xrm.Page.getAttribute("cld_billingenddate").setValue(endDate);
    if (Xrm.Page.getAttribute("cld_licencestartdate").getValue() == null)
        Xrm.Page.getAttribute("cld_licencestartdate").setValue(Date.now());
    if (Xrm.Page.getAttribute("cld_licenceenddate").getValue() == null)
        Xrm.Page.getAttribute("cld_licenceenddate").setValue(endDate);
}


What is the best way to resolve this? This is CRM Online 8.2 currently.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello Try to use following code:

    function SetDefaultDates() {
        console.log("Set Default Dates");
        console.log("End Dates: now + 90 days");
        var daysToAdd = 90;
        var nowDate = new Date();
        console.log(nowDate);
        nowDate.setDate(nowDate.getDate() + daysToAdd);
        console.log(endDate);
        if (Xrm.Page.getAttribute("cld_billingstartdate").getValue() == null)
            Xrm.Page.getAttribute("cld_billingstartdate").setValue(Date.now());
        if (Xrm.Page.getAttribute("cld_billingenddate").getValue() == null)
            Xrm.Page.getAttribute("cld_billingenddate").setValue(nowDate);
        if (Xrm.Page.getAttribute("cld_licencestartdate").getValue() == null)
            Xrm.Page.getAttribute("cld_licencestartdate").setValue(Date.now());
        if (Xrm.Page.getAttribute("cld_licenceenddate").getValue() == null)
            Xrm.Page.getAttribute("cld_licenceenddate").setValue(nowDate);
    }


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans