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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Calculation of today's date in yyyy-MM-dd format.

(1) ShareShare
ReportReport
Posted on by

Hello Experts,

The below lines of code working fine in my JS Webresource function.But same is not working when i embed these lines in a function which is present in an html file .


var d = new Date();
var DateJour=new Date(d.getFullYear(),d.getMonth(),d.getDate(), 0, 0, 0, 0);
var frmatedDateJour = DateJour.format('yyyy-MM-dd');

There is no error,but variables DateJour and  frmatedDateJour have nothing calculated though i am getting date in var d .

Any clue?

I want to calculate today's date in yyyy-MM-dd format.

*This post is locked for comments

I have the same question (0)
  • Dynamics365 Rocker Profile Picture
    7,755 on at

    Try to debug your script.

  • Community Member Profile Picture
    on at

    Hi Rocker,

    Please help me find the bug.Debugging seems not to be helping.Following code working absolutely fine when i pack it in a JS file and run on form onload for ex.but there is an html file in my default solution.I m in need to embed this code there because i want to calculate this on click of a button :

    function NextPlannedCallOnload() {

    var currentAccount=window.parent.Xrm.Page.getAttribute("name").getValue();

    var d = new Date();

    var DateJour=new Date(d.getFullYear(),d.getMonth(),d.getDate(), 0, 0, 0, 0);

    var frmatedDateJour = DateJour.format('yyyy-MM-dd');

    if (currentAccount != null) {

          var currentAccountId = window.parent.Xrm.Page.data.entity.getId();

    }

    var callPlanFetchXML="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+

     "    <entity name='appointment'>"+

       "        <attribute name='subject' />"+

       "        <attribute name='statecode' />"+

       "        <attribute name='scheduledstart' />"+

       "        <attribute name='ownerid' />"+

       "        <attribute name='scheduledend' />"+

       "        <attribute name='createdon' />"+

       "        <attribute name='activityid' />"+

       "        <attribute name='regardingobjectid' />"+

       "        <order attribute='regardingobjectid' descending='false' />"+

       "        <order attribute='scheduledstart' descending='false' />"+

       "        <filter type='and'>"+

         "            <condition attribute='scheduledstart' operator='next-x-years' value='1' />"+

         "             <condition attribute='statecode' value='3' operator='eq'/> "+  

         "            <condition attribute='scheduledstart' operator='on-or-after' value='"+currentAccountId+"'/>"+

        "           <condition attribute='regardingobjectid' operator='eq'  value='"+frmatedDateJour+"'/>"+

       "        </filter>"+

     "    </entity>"+

    "</fetch>";

    var callPlanRecords = XrmServiceToolkit.Soap.Fetch(callPlanFetchXML);

    if (callPlanRecords.length == 0)

    Xrm.Page.getAttribute("new_nextplannedcall").setValue(" ");

    if (callPlanRecords.length >0) {

    if (callPlanRecords[0].attributes.scheduledstart != undefined || callPlanRecords[0].attributes.scheduledstart != null)

    {

       var NxtAppDate=callPlanRecords[0].attributes.scheduledstart.value;

    Xrm.Page.getAttribute("new_nextplannedcall").setSubmitMode("always");

    Xrm.Page.getAttribute("new_nextplannedcall").setValue(NxtAppDate);

    }

    }

    }

    Let me know if any input needed from my end.

  • Community Member Profile Picture
    on at

    Rocker,

    The control from below line :

    var callPlanRecords = XrmServiceToolkit.Soap.Fetch(callPlanFetchXML);

    is going back to caller.

    Something fishy here :/ Any clue,pls??

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Kavita,

    Could you please debug your code and share the error here.

  • Dynamics365 Rocker Profile Picture
    7,755 on at

    Please make sure that you are getting value in below variables:

    var currentAccount=window.parent.Xrm.Page.getAttribute("name").getValue();

    var currentAccountId = window.parent.Xrm.Page.data.entity.getId();

    Also share error details

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Kavita,

    There is small a silly mistake ,  you did not set correct attribute value in the condition statement of FetchXML , its should be reverse .  See the condition value corrected in below code highlighted . In addition I have removed space from FetchXML.

            function NextPlannedCallOnload() {
                var currentAccount = window.parent.Xrm.Page.getAttribute("name").getValue();
                var d = new Date();
                var DateJour = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
                var frmatedDateJour = DateJour.format('yyyy-MM-dd');
                if (currentAccount != null) {
                    var currentAccountId = window.parent.Xrm.Page.data.entity.getId();
                }
    
                var callPlanFetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                 "<entity name='appointment'>" +
                   "<attribute name='subject' />" +
                   "<attribute name='statecode' />" +
                   "<attribute name='scheduledstart' />" +
                   "<attribute name='ownerid' />" +
                   "<attribute name='scheduledend' />" +
                   "<attribute name='createdon' />" +
                   "<attribute name='activityid' />" +
                   "<attribute name='regardingobjectid' />" +
                   "<order attribute='regardingobjectid' descending='false' />" +
                   "<order attribute='scheduledstart' descending='false' />" +
                   "<filter type='and'>" +
                     "<condition attribute='scheduledstart' operator='next-x-years' value='1' />" +
                     "<condition attribute='statecode' value='3' operator='eq'/> " +
                     "<condition attribute='scheduledstart' operator='on-or-after' value='" + frmatedDateJour + "'/>" +
                    "<condition attribute='regardingobjectid' operator='eq'  value='" + currentAccountId + "'/>" +
                   "</filter>" +
                 " </entity>" +
                "</fetch>";
    
                var callPlanRecords = XrmServiceToolkit.Soap.Fetch(callPlanFetchXML);
                if (callPlanRecords.length == 0)
                    Xrm.Page.getAttribute("new_nextplannedcall").setValue(" ");
                if (callPlanRecords.length > 0) {
                    if (callPlanRecords[0].attributes.scheduledstart != undefined || callPlanRecords[0].attributes.scheduledstart != null) {
                        var NxtAppDate = callPlanRecords[0].attributes.scheduledstart.value;
                        Xrm.Page.getAttribute("new_nextplannedcall").setSubmitMode("always");
                        Xrm.Page.getAttribute("new_nextplannedcall").setValue(NxtAppDate);
                    }
                }
            }

  • Community Member Profile Picture
    on at

    Thanks Gautam,

    But i was reversed only.Its just that while debugging i may have removed the condition and then while posting here i did not notice.Anyway thanks but it does not help.

    I have figured out that date calculation is not working in the html page where i am embedding the Java Script function so i have referenced some libraries as shown below but still no luck.Can you guide me what all libraries to refer in my html head tag and how to refer.There is some obvious thing that i am missing and I need your help .

    Thanks in advance!!

  • Community Member Profile Picture
    on at

    Hi Rocker,

    Yes these Variables are getting current values.

    I have figured out that date calculation and fetch xml is not working in the html page where i am embedding the Java Script function so i have referenced some libraries as shown below but still no luck.Can you guide me what all libraries to refer in my html head tag and how to refer.There is some obvious thing that i am missing and I need your help .

    <script language="javascript" type="text/javascript">

    <script src="../../WebResources/uxc_XrmServiceToolkit" type="text/javascript"></script>

    <script src="../../WebResources/uxc_JQuery" type="text/javascript"></script>

    <script type="text/javascript" src="../../ClientGlobalContext.js.aspx"></script>

    Thanks in advance!!

  • Community Member Profile Picture
    on at

    <script language="javascript" type="text/javascript">

    <script src="../../WebResources/uxc_XrmServiceToolkit" type="text/javascript"></script>

    <script src="../../WebResources/uxc_JQuery" type="text/javascript"></script>

    <script type="text/javascript" src="../../ClientGlobalContext.js.aspx"></script>

    The exception is xrmservice toolkit is not defined :( even after referencing the library.

  • Community Member Profile Picture
    on at

    The exception is xrmservice toolkit is not defined :( even after referencing the library.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans