This is a migrated thread and some comments may be shown as answers.

Pass Date time Report parameter to web service data source

1 Answer 499 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tally
Top achievements
Rank 1
Tally asked on 30 Jul 2019, 10:31 AM

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

1 Answer, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 02 Aug 2019, 08:14 AM

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
Tags
General Discussions
Asked by
Tally
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Share this question
or