Pass Date time Report parameter to web service data source

2 posts, 0 answers
  1. Tally
    Tally avatar
    6 posts
    Member since:
    Apr 2019

    Posted 30 Jul Link to this post

    I have an application that has an angular 6 client with telerik reporting viewer,and C# api server.
    I have created a report with the report designer. the report has 2 dateTime parameters defined like in the snapshot: 
    Now, I use it in the web service data source like on the other  snapshot

    So far so good.
    I update the parameters value from my clients this way:
    let rs =

    {

    report: this.reportName,

    authenticationToken: token,

    parametersAreaVisible: true,

    parameters: {

         networkItemsKeys: JSON.stringify(parameters.tags),

         token: token, userName:this.userName,

         toDate: parameters.toDate,

         fromDate: parameters.fromDate } }

          as unknown as JSON;

          this.reportSource = rs; this.reportViewer.setReportSource(rs);

        parameters.toDate is DateTime property. 
    I can see that the date parameters are updated fine when looking at a textbox defined this way:
    Report Period: {Parameters.fromDate.Value.toShortDateString()}-{Parameters.toDate.Value.toShortDateString()}
    The problem is that when I check the value that is received in my web api has month and days switched so if the day is greater than 12 the parameter value is 1/1/0001. I have tried all sorts of datepipe format changes, with no success.
    The problem is solved when I use the toDate and fromDate as string parameters, but is seems like a stupid solution, and that way I can't use the date type abilities like .toShortDateString() in the text box. Any ideas?
    TX Tal

  2. Nasko
    Admin
    Nasko avatar
    1070 posts

    Posted 02 Aug Link to this post

    Hi Tally,

    It is possible that the culture and regional settings on the Reporting server where the report is rendered are different from the settings on the Web API server. You can inspect the requests made from the client to the Reporting server, and then from the Reporting server to the Web API server using Fiddler and check the format of the date in the request. Also check if one of the servers uses US date format (MM/dd/yyyy) and another server uses the dd/MM/yyyy format. When a date variable travels via an HTTP request, it is converted to a JSON string and then parsed back to a date object by the Web API. It is possible that the JSON string is interpreted differently depending on the machine culture and regional settings.

    Regards, Nasko
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top