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

edit expressions in Telerik reports

15 Answers 748 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kaushal
Top achievements
Rank 1
kaushal asked on 06 Nov 2007, 07:29 AM
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 ????

15 Answers, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 06 Nov 2007, 10:38 AM
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
0
kaushal
Top achievements
Rank 1
answered on 14 Nov 2007, 05:21 AM
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.
0
Milen | Product Manager @DX
Telerik team
answered on 14 Nov 2007, 12:45 PM
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
0
Maxime
Top achievements
Rank 1
answered on 16 Nov 2007, 03:40 PM
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,


0
Milen | Product Manager @DX
Telerik team
answered on 19 Nov 2007, 01:17 PM
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
0
Maxime
Top achievements
Rank 1
answered on 19 Nov 2007, 02:07 PM
Thanks,

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

Regards,
0
kaushal
Top achievements
Rank 1
answered on 21 Nov 2007, 05:07 AM
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.
0
Milen | Product Manager @DX
Telerik team
answered on 22 Nov 2007, 08:35 AM
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
0
Milen | Product Manager @DX
Telerik team
answered on 22 Nov 2007, 09:17 AM
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
0
Wendy Hunt
Top achievements
Rank 2
answered on 05 May 2010, 07:52 PM
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
0
Peter
Telerik team
answered on 06 May 2010, 12:15 PM
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.
0
Wendy Hunt
Top achievements
Rank 2
answered on 06 May 2010, 03:17 PM
Thanks Peter!  It was a piece of cake after I knew where to go.
Thanks for the information!  
:)

wen
0
Kirti
Top achievements
Rank 1
answered on 13 Apr 2020, 03:40 PM

I need to change the datasource for one field in a report. The fields adjacent to the one I want to change have the correct datasource. The datasource in the "Fields" section of the edit expression dialog seems to be read only. How do I change the datasource for that one field?

 

 

0
Kirti
Top achievements
Rank 1
answered on 13 Apr 2020, 04:11 PM
How would that be done in VB.NET?
0
Todor
Telerik team
answered on 15 Apr 2020, 01:29 PM

Hello Kirti,

The 'Fields' Global Object gets its possible values from the data source of the inner-most parent data item - see Expression scope. It is possible to use data from other, outer parent data items through the user functions that accept 'scope', for example, 'Exec' Data function. You may also use custom user functions to provide the necessary values.

Regards,
Todor
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
General Discussions
Asked by
kaushal
Top achievements
Rank 1
Answers by
Svetoslav
Telerik team
kaushal
Top achievements
Rank 1
Milen | Product Manager @DX
Telerik team
Maxime
Top achievements
Rank 1
Wendy Hunt
Top achievements
Rank 2
Peter
Telerik team
Kirti
Top achievements
Rank 1
Todor
Telerik team
Share this question
or