I have a user function that returns an object with a lot of calculated fields that are expensive to call each time. Is there a way to call the function one time and save the results so that it doesn't get called multiple times as I display the fields on the report?
There are at least 10 individual text fields that are displayed on the report that all come from the user function.
Thanks.
7 Answers, 1 is accepted
The user function will be called as many times as there are expressions in the report which are calling it. This is the behavior of the user functions by design. If you share more information on the user function definition we might be able to suggest ways to optimize the code inside, or replace the user function with another functionality.
Regards,
Nasko
Telerik
Yes, I see that it's called multiple times. I was hoping to save the results of the call so that I can display multiple fields with data that comes from the user function. In my case, the user function is returning an object with many fields such as ProcessDate, Status, StatusDate, Description, Title, Summary...
The user function is getting this data from both sql and info in a redis cache and would not easily be added to the sql stored procedure that drives the report.
I've also tried binding the report to the object directly as a second data source, but no matter what I've done, the wizard doesn't show any of my business objects.
You can call the user function once and store the result inside a property of the report, or a report parameter. The approach is demonstrated in the attached project.
Regards,
Nasko
Telerik
Thanks for the code, however, I think there are a few issues.
1. When I create a parameter, my choices of type do not include object. In my description, I mentioned that the user function returns an object with many fields.
2. Each row of the report needs to call the user function with a different parameters. It looked like I could not reference the field values when creating the report parameter.
Any other ideas? This might be a show-stopper for our review of Telerik Reporting.
Thanks,
Rick
There are other possible solutions which are out of the scope of Telerik Reporting. For example, you can create a single complex object with precalculated data for all of the current report class instances and reuse the object inside the user function method. Attached you can find a sample project demonstrating the approach.
Regards,
Nasko
Telerik
Two questions again:
1. Does this technique work using the stand-alone report definitions (trdx files)?
2. In my case, the expensive object needs to be reevaluated each time the group header changes. Is that possible?
Thanks,
Rick
1. The Standalone Report Designer can work only with XML report definitions (TRDX). The technique is not applicable to TRDX reports.
2. You can call another user function inside the group header and trigger the re-evaluation using code when the value of a field changes.
Regards,
Nasko
Telerik