web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    RE: Javascript Set Default Date in 90 days

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans