Fetching records doesn't get latest

7 posts, 1 answers
  1. Sulu
    Sulu avatar
    34 posts
    Member since:
    Aug 2013

    Posted 14 Apr 2014 Link to this post

    Hi, everyone!
    When I attempt to get records created in the last 72 hours from Backend Services, I can't see the records for the past day. Is there a reason for this? I'm seeing records that are older than 24 hours, just not anything new in the past 24. My query looks like this:

    TimeSpan timespanvalue = new TimeSpan(72, 0, 0);
    DateTime dt = DateTime.Now.Subtract(timespanvalue);

    var temp = await app.WorkWith().Data<Timesheet>().Get().Where(t  => t.StartTime > dt).IncludeFields(t => t.Id).IncludeFields(t => t.Employee).ExecuteAsync();
  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 15 Apr 2014 Link to this post

    Hi Sulu,

    The query you have registered is valid in the context of Backend Services. We have tried to reproduce the error, but to no success.

    Are you still experiencing the issue?

    From your post seems that the StartTime field is properly de-serialized and you are obtaining the records with starting time in the past 72 hours, but not all of them (these from the last 24 hours). Could you please specify the data structure of the records that are expected to appear in the result but does not appear, is it different than the structure of the previous entries? Could this be related to the lack of records that match the query filter?

    Thank you in advance.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  3. Sulu
    Sulu avatar
    34 posts
    Member since:
    Aug 2013

    Posted 15 Apr 2014 in reply to Anton Dobrev Link to this post

    Hi, Anton! Well, I have updated information on this issue. Yes, I'm still seeing it. But it is also happening for older records. However, if I go online and edit the record without changing it (in my browser), then I save the record, the .NET application is able to fetch it. So there is something about saving the record through the browser client that does something that then allows my query to work. How maddening, ey?
    Here is the structure of my record. The table name is Timesheet. The application tracks clock-ins and clock-outs for employees.
    Aside from those fields automatically created are these fields:
    AuditInfo   Text
    Employee Text
    IsOnClock Yes/No
    KnownLocation Text
    Location    Geopoint
    Note           Text
    ServiceOrder     relation (multiple)
    StartTime    DateTime
    Text            Text  (this was a test field, added after the bug was appearing)
    Title             Text
    Type           Number






  4. Sulu
    Sulu avatar
    34 posts
    Member since:
    Aug 2013

    Posted 15 Apr 2014 in reply to Sulu Link to this post

    ... also, the past 24-hours problem is still there. Even if I update the record in the browser, by clicking Edit then Save, I still can't fetch the record. So I'm chasing two bugs now. 
  5. Answer
    Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 16 Apr 2014 Link to this post

    Hello Sulu,

    The issues you are experiencing are most probably connected to existing records in the content type whose StartTime field is saved to the database as a common string, and not as a Date. This results in unexpected comparison of the items on their StartTime on a database level. 

    You can check this by retrieving all Timesheet items with a tool like Postman or Fiddler, and observe the JSON objects in the result. These that adhere to the structure will have a "StartTime" value in the standard UTC format "2014-04-16T08:36:20.618Z". These whose "StartTime" was not properly entered will have a value, for example, like "2014/04/16". The latter will not be evaluated as dates when making a date-based comparison.

    Could you could revise the implementation of the .NET Timesheet model class and the method that inserts the Timesheets to Backend Services in regard to the proper serialization of the StartTime property? Also, is there any cloud code relevant for the insertion of data in this content type?

    If this does not solve the issues, we would appreciate if you could share the aforementioned code.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  6. Sulu
    Sulu avatar
    34 posts
    Member since:
    Aug 2013

    Posted 17 Apr 2014 in reply to Anton Dobrev Link to this post

    Ah ha! I think you have it pegged, sir! I checked the client code to see how the time is getting entered and this is what I found:
    var currentdate = new Date();
    var eventTime = currentdate.toLocaleString();

    ... where the eventTime is being used in the datasource as the StartTime field. I'll fix it and give it a test.

    Thanks so much!
  7. Sulu
    Sulu avatar
    34 posts
    Member since:
    Aug 2013

    Posted 17 Apr 2014 in reply to Sulu Link to this post

    I made the change and performed a test. Your suggestion works! I worship the ground you walk on!
    -sulu
Back to Top