edit expressions in Telerik reports

13 posts, 0 answers
  1. kaushal
    kaushal avatar
    3 posts
    Member since:
    Nov 2007

    Posted 06 Nov 2007 Link to this post

    I m unable to carry out many functions in Telerik report. I tried to carry out subtraction between dates or times, and unable to carry out if - else operation on the fields. please help me out with the above mentioned issues.

    these features are available in crystal reports, then why not in Telerik reports. and if these operations can be carried out in Telerik reports, then please guide me how to do this ????
  2. Svetoslav
    Admin
    Svetoslav avatar
    649 posts

    Posted 06 Nov 2007 Link to this post

    Hello kaushal,

    This is a known issue with the built-in expression engine. However, there is a possible workarround that you can use. You can define and use your own function (user defined function) that subtract dates, then use it in any expression.

    Here is an example:

    class Report1
    {
        ...
       
        public static object SubtractDates(DateTime date1, DateTime date2)
        {
            return (date1 - date2);
        }
    }

    and use it in any expression like this:

    =SubtractDates(Fields.ToDate, Fields.FromDate)

    where FromDate and ToDate are data fields of the report's data source.

    Actually the great thing about User Defined Functions is that you can always use them to overwrite or extend the default script engine capabilities.

    I hope this information helps. Thank you.

    Regards,
    Svetoslav
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. DevCraft banner
  4. kaushal
    kaushal avatar
    3 posts
    Member since:
    Nov 2007

    Posted 13 Nov 2007 Link to this post

    Thanks a lot for your great support.
    I am having one more issue with the Average of "Time" value. I use "AVG" function from the "expreesions" field. But it doesnt give me the required result i.e. in the "hh:mm:ss" format. I even tried the "Custom Formatting option, but it gives me the output printed as "hh:mm:ss" where the output should be like "00:10:56". Please help me out with this issue.

    Thanking you in anticipation.
  5. Milen
    Admin
    Milen avatar
    163 posts

    Posted 14 Nov 2007 Link to this post

    Hi kaushal,

    Usually this kind of problems occur when you try to apply unsuitable format string for given data type. For example if you try to use format string {0:hh:mm:ss} on Int value. You can try to review what data type your expression returns and apply appropriate formatting on it.

    If that does not help, please send us a little more info like: what exactly is the expression you want to format, what data type is every field in it, etc.

    Thank you in advance.

    Best wishes,
    Milen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Maxime
    Maxime avatar
    30 posts
    Member since:
    May 2006

    Posted 16 Nov 2007 Link to this post

    Hi,

    What are authorized prototypes for user functions ?

    I noticed that :
    public static string GetStr(object str)     
    {     
        return str.ToString();     
    }  
     


    works but simply :

    public static string GetStr(string str)     
    {     
        return str;  
    }     
        
     

    does'nt works. The string returned is always empty.

    Best regards,


  7. Milen
    Admin
    Milen avatar
    163 posts

    Posted 19 Nov 2007 Link to this post

    Hi Sébastien FLEURIET,

    Here you can review examples of user defined functions. The most important is to be careful what type is the value you are providing as parameter.

    In the first code snippet of yours if you provide for example DateTime value as parameter the ToString() method will format the value as date and time and the result will be what you expected. In the second one if the value provided is DateTime, during the processing of the report the report engine will search your code for method with signature public static GetStr(DateTime), which will not be found, so you will not get the expected result.

    What I would do is to review the expressions - data types especially, or even debug and see if the debugger enters your user function.

    Sincerely yours,
    Milen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Maxime
    Maxime avatar
    30 posts
    Member since:
    May 2006

    Posted 19 Nov 2007 Link to this post

    Thanks,

    You saw right with DateTime type.  I better understand now...

    Regards,
  9. kaushal
    kaushal avatar
    3 posts
    Member since:
    Nov 2007

    Posted 20 Nov 2007 Link to this post

    Hey .... thanks.
    1. >>   I am actually trying to take out the average of time in "seconds" and then want it to get displayed in format :: hh:mm:ss.
    2. >>   And also I am not able to take out the average of Time value which is in format :: hh:mm:ss.
    Please help me out with these both issues.

    Thanking you in anticipation.
  10. Milen
    Admin
    Milen avatar
    163 posts

    Posted 22 Nov 2007 Link to this post

    Hello kaushal,

    In TextBox ReportItem the formatting is set in the Format Property and the format specified is applied on the value of the TextBox during processing of the report.
    It is really important that the format string applied is suitable to the data type of the value.

    In your case, your value is seconds, which probably is a long type. So, you are trying to apply format string {0:hh:mm:ss} on a long value. This format is suitable for DateTime and TimeSpan types, so I would use a user defined function to convert the seconds in TimeSpan.

    Something like

            public static object ToTimeSpan(object seconds)
            {
                if (DBNull.Value == seconds)
                    return DBNull.Value;
                else
                    return new TimeSpan((long)(TimeSpan.TicksPerSecond * (double)seconds));
            }


    and use it in the expression of the Value Property of the TextBox.

    Additional information:
    Using Expressions - here you can find more info on formatting and using user defined functions in our product .
    Date and Time Format Strings - here you can find info about format strings usable with date and time values.

    I hope this information helps. Please, let me know if I can assist you any further.
    Thank you.

    Greetings,
    Milen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  11. Milen
    Admin
    Milen avatar
    163 posts

    Posted 22 Nov 2007 Link to this post

    Hello kaushal,

    In addition to my previous message, you can get the Average of the seconds and then convert the returned value to TimeSpan.

    In the details something like:
    =ToTimeSpan(seconds)

    In the group footer:
    =ToTimeSpan(Avg(seconds))

    Then apply the preferred formatting in the Format property of the text boxes.

    Thank you again.

    Regards,
    Milen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  12. Wendy Hunt
    Wendy Hunt avatar
    50 posts
    Member since:
    Nov 2009

    Posted 05 May 2010 Link to this post

    Milen -

    I have a report field for a datetime that I want to remove the timestamp on.  The timestamp is coming from the database.  I went to ConditionalFormatting for the Field and created a new Rule.  It is:

    Expression:
    =Fields.[SubmittalDate]

    Operator:
    =

    Value:
    =Fields.[SubmittalDate].Date.Trim(hh:mm:ss)

    It is not working to remove the timestamp.  How do I correctly Trim the timestamp off of the date?

    Thanks -
    wen
  13. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 06 May 2010 Link to this post

    Hi Wendy Hunt,

    Conditional formatting lets you dynamically style report items based on rules that you define in the Conditional Formatting Rules Dialog. This lets you change the visual appearance of the report based on changing conditions in the report without the need for coding events. 

    The recommended way to suppress the timestamp is by setting an appropriate Format . The Format Builder dialog allows you to apply formatting to the TextBox and CheckBox items. You can open that dialog either from the property grid of those items or from their context menu, by selecting the Format menu item.

    All the best,
    Peter
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  14. Wendy Hunt
    Wendy Hunt avatar
    50 posts
    Member since:
    Nov 2009

    Posted 06 May 2010 Link to this post

    Thanks Peter!  It was a piece of cake after I knew where to go.
    Thanks for the information!  
    :)

    wen
Back to Top
DevCraft banner