locked
JavaScript - FetchXML - GetDate RRS feed

  • Question

  • Hi,

    I am fetching data from the Entity using FetchXML - JavaScript, the thing is that I also wanna fetch todays date. Whatsoever is the best approach can be adopted any of following with max candidature will do,

    SYSDATETIME() ,SYSDATETIMEOFFSET() ,SYSUTCDATETIME() ,CURRENT_TIMESTAMP ,GETDATE() ,GETUTCDATE();

    Thanks and Regards,

    Rk_Hirpara


    Friday, July 8, 2016 10:21 AM

All replies

  • Hi Hirpara,

    If you want the current date using javascript you can just use;

    var currentDate = new Date();

    If there is a specific reason you are wanting to retrieve it using FetchXML please explain further.

    ~ Nathan

    Saturday, July 9, 2016 10:03 AM
  • Nathan,

    Thanks for your reply,

    new Date() of the javascript would take clients system date which is in control of the client, while I would like to use date as per the server.

    Let say, I wanna set some target and target setting should be allowed to set for the current month only. Now if I do this by javascript new Date() then a smart user can alter the past target as well, as date is in his/control.

    in short, date here is security critical, so client should not be the contributor of the date, but the server, does it make sense?

    Even it is not constrain to use the FetchXML but the preference.

    Thanks and Regards,

    Rk_Hirpara



    • Edited by RkHirpara Monday, July 11, 2016 11:25 AM updated
    Monday, July 11, 2016 11:13 AM
  • MaKeer,

    Thanks for your reply,

    But your reply doesn't satisfy my requirement as new Date() cant not used "for same" as far as client and server are on the different machine.

    Thanks and Regards,

    Rk_Hirpara

    Monday, July 11, 2016 11:20 AM
  • Hi Hirpara,

    Business critical logic should not be controlled via javascript alone as any client-side scripting can be tampered with or disabled.

    A good approach in this scenario would be to use javascript to set the values so the user can see what is happening (for this you can use new Date()), but validate them using a plugin. This means the client-side scripting is only there for cosmetic purposes while the plugin is setting the final values.

    ~ Nathan

    Wednesday, July 13, 2016 8:59 PM
  • Hi Nathan,

    Again thanks for sharing your idea, here this is not the concern as if javaScript disabled it wont work at all the functionality depends on JS, secondly this functionality is not for technical people and as altering JS is not this handy no fear, however discussing on this we are diverting from the subject of the question.

    The question is how to get DataBase server date in the browser using JS, irrespective to reason for doing it. Please help here.

    Thanks and Regards,

    Rk_Hirpara

    Friday, July 15, 2016 5:46 AM
  • Hi Hirpara,

    Have you checked This

    Hope this helps.

    Thanks

    Friday, July 15, 2016 12:54 PM
  • Does not matter what Server time zone is, as far as User Timezone is correctly set up in CRM, it will be taken care of.

    MaKeer | myencounterwithcrm.wordpress.com | CRM2011 User Settings Utility | CRM2011 Lookup Preview | CRM2011 Lookup Attribute Mapping | CRM2011 TreeView Control (Beta) | CRM2011 N:N Entity View (Beta) | CRM 2011 Global Quick Search (Beta)

    Monday, July 18, 2016 3:43 AM