use of dateTime as parameter for WebApiDataSource

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

    Posted 01 Aug 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 picture attached.

    Now, I use it in the web service data source like in the other picture.

    So far so good.

    I update the parameters value from my clients like in the third image.

     

    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?
  2. Eric R | Technical Support Engineer
    Admin
    Eric R | Technical Support Engineer avatar
    130 posts

    Posted 05 Aug Link to this post

    Hi Tally,

    The string format works because when using a JSON based data source the values are all strings. There are a couple of options to work around this and I have listed them below. 

     Option 1 (Recommended)

    Use the built in Parameters Area to set parameters for the report and data source. I have attached a sample project that displays how to do this and provided additional information below.

    This method will require converting the date formats using the provided Conversion Functions. For example, if the report parameter is in the DateTime format. The Web Service Query would look like the following screenshot. Doing this will convert the parameter value to a string format which matches the API input parameter.

    Additionally, it will require converting the string formats to the desired value and setting the format properties in the report. See below screenshots for more information.

    The Table:

    The Table TextBox Properties:

     Option 2

    Convert the DateTime parameter to a Date prior to passing the parameter to the report. More information is available at the Converting string to Date Stack Overflow thread.

    To test the attached sample, I recommend setting up the Telerik NugetFeed in Visual Studio. 

    Please let me know if you need any additional information. Thank you for using Telerik Reporting.

    Regards,

    Eric R
    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