I'm new to Telerik reporting and I'm haveing a problem with the expressions. I have 3 textboxes with number values and 1 other textbox that woill be the total of the 3. But when I run the report it gives me an error "The expression contains object "fldMMHQ_USD" that is not defined in the current context". I don't understand. The textbox is there, I see the values, but the "Total" textbox doesn't seem to the others. Here is my expression: = fldMMHQ_USD + fldMM_USD + fldEMPR_USD. Thanks for the help
7 Answers, 1 is accepted
I suppose you have 3 TextBox items in your report which are data-bound to 3 different fields from a data source. To compute the sum of them via an expression, you need to specify the fields from the data source in the expression, not the TextBox items. For example, lets assume you have the following 3 fields in the data source: Field1, Field2, Field3; and you have the following 3 TextBox items in the report: TextBox1, TextBox2, TextBox3.
Item |
Field |
Expression |
TextBox1 |
Field1 |
= Fields.Field1 |
TextBox2 |
Field2 |
= Fields.Field2 |
TextBox3 |
Field3 |
= Fields.Field3 |
In this case the correct expression syntax to sum the 3 fields would be the following one:
= Fields.Field1 + Fields.Field2 + Fields.Field3
A more detailed explanation about using expressions can be found in the next section of the online documentation: Expressions. Please, pay close attention to the following help topic in the same section which discusses the global objects recognized by the expression engine and the correct syntax how to access them: Global Objects.
Hope this helps.
All the best,
Ivan
the Telerik team
Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.
Ex: Textbox1.Value = 25.26
TextBox2.Value = 1.0536
What I want to do in Textbox 3 is as follows:
Textbox3 = Textbox1.value * Textbox2.value
But I want to do it in the expression and not in the code behind. Hope this explanation is a little more clear. Thanks for the help
I am not quite certain I understand your inquiry correctly. In theory nothing stops you from implementing a user function that finds a specific item in the processing tree by name and use it in your expressions. The problem with this approach is that it is too error prone, because it depends solely on the order the items are being processed by the reporting engine. For example, if TextBox3 is processed after both TextBox1 and TextBox2 your expression would work as expected, however if TextBox3 is processed before TextBox1 or TextBox2 the expression would produce an incorrect result, because TextBox1 or TextBox2 might not have a valid value yet. That is part of the reason why we do not expose the report items directly in expressions.
If you have a hard-coded constant you want to reuse in expressions you can always create a hidden ReportParameter with a default value set to that constant and then use the ReportParameter in the expressions instead. This approach also has the side benefit that you can easily pass a different value for the constant from outside the report.
Best wishes,
Ivan
the Telerik team
Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.
My colleague already provided all the necessary information you need to get this working and similar examples are already present in the Expressions as Values of Item Properties help article. If you're still having problems, it would be best to open a support ticket and attach a sample report that shows what you do, and we would advise you accordingly.
Best wishes,
Steve
the Telerik team
Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.
Hi Ivan,
I think you provided necessary information to workaround the core issue of this thread, but I still think that there should be a better way.
I have one TextBox that has a bit complicated formula, using SUM, IIF, or COUNT, and I would like to reuse that value in many other TextBoxes. In order to do that I need to have all these TextBoxes include the complicated formula addition to some other values that is unique in each TextBox.
Is there any way I can set the value in a report footer section that can be referred by other TextBoxes?
You can use a user function that performs the complex calculations and returns the result. Details how to load user functions in the Standalone Report Designer are available in Extending Report Designer.
Please feel free to log a feature request for having re-usable custom expressions in the Expression Editor. Features are considered for implementation based on the demand.
Regards,
Stef
Telerik by Progress