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)

Retrieving the data by passing date and time attribute using Web Api

(0) ShareShare
ReportReport
Posted on by 307

Hi Experts,

We have fields called start time and End Time(Date and Time).when ever user entering time sheet record with start time and end time ,we need to restrict if time overlapping with existing records.I have tried with filter query(Web API) for matching records to find duplication,but i am not able to get records for date and time field.

Please help me on this to resolve the issue.

Thanks in advance.


Best Regards,
Seenivasan

*This post is locked for comments

I have the same question (0)
  • Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    Would you please the paste the code here?

  • Seenivasan M Profile Picture
    307 on at

    Hi,

    Please find my code below,

    var startTime = Xrm.Page.getAttribute("new_starttime").getValue();

    var GetDataQuery = "new_timesheets?$select=new_starttime,new_endtime&$filter=new_starttime ne null and new_endtime ne null and new_starttime eq " + startTime + ""

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Sreenivasan,

    In order to query date time fields, it should be in ISO string format. Try the code below.

    Try the code below.

    var startTime = Xrm.Page.getAttribute("new_starttime").getValue();
    var startTimeISO = startTime.toISOString();
    var startTimeFormat = startTimeISO .replace(startTimeISO .substring(19, 23), "");
    var GetDataQuery = "new_timesheets?$select=new_starttime,new_endtime&$filter=new_starttime ne null and new_endtime ne null and new_starttime eq datetime'" + startTimeFormat + "'";

    See: msdn.microsoft.com/en-us/library/gg309461(v=crm.7).aspx#BKMK_filter

    Hope this helps.

  • Suggested answer
    Community Member Profile Picture
    on at

    Refer this:

    http://missdynamicscrm.blogspot.sg/2014/05/crm-2011-crm-2013-odata-datetime.html

  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    The following format works.

    You need to convert all the dates to UTC (Z).

    https://<orgname>.api.crm4.dynamics.com/api/data/v8.2/accounts?$filter=createdon%20ge%20(2017-05-15T08:00:00Z)%20and%20createdon%20le%20(2017-05-15T08:54:00Z)

    Refer the following as well:

    missdynamicscrm.blogspot.co.uk/.../crm-2011-crm-2013-odata-error-when.html

  • Seenivasan M Profile Picture
    307 on at

    Hi Nithya Gopinath,

    Thank you for your quick response.

    I have tried your code and i am getting null response from web Api request.

    Err message: failed to load resource the server responded with a status of 404(bad request)

  • Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    What is the value for GetDataQuery you are getting, when debugging?

  • Seenivasan M Profile Picture
    307 on at

    Gopalan Bhuvanesh,

    Please find the value of GetDataQuery below,

    "new_entity2s?$select=new_starttime,new_endtime&$filter=new_starttime ne null and new_endtime ne null and new_starttime eq datetime'2017-05-09T02:30:00Z'"

    Thanks and Regards,

    Seenivasan

  • Suggested answer
    Community Member Profile Picture
    on at

    Is you entity name new_entity2s  ?? Also please make sure you have data for above mentioned start time. I would recomment you to use ge operator.

    "new_entity2s?$select=new_starttime,new_endtime&$filter=new_starttime ne null and new_endtime ne null and new_starttime ge datetime'2017-05-09T02:30:00Z'  and new_endtime le datetime'2017-05-09T02:30:00Z'"

  • Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    Try the following directly in the browser and test.

    Change the root url to your organization (both <orgname> and <crm>):

    https://<orgname>.api.<crm>.dynamics.com/api/data/v8.2/new_entity2s?$select=new_starttime,new_endtime&$filter=new_starttime ne null and new_endtime ne null and new_starttime eq (2017-05-09T02:30:00Z)

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