Then we add the new element to the report.
Now, where we add elements is important. Remember the Phases from earlier
examples. Well, you cannot add new elements after the factory phase. So that means
if we look at the Report Root, we can only use the code in the initialize Event from
the previous example (or in the beforeRender and the beforeFactory Events). The
afterFactory and afterRender Events will not work. If we move the code to those
elements, then the element will not get added.
One other thing to notice: if you look in the beforeFactory Event, you will notice
that the Context that points to the IReportDesign object is available, but it is not
available in any of the other Events. When working with reports through Scripting,
remember that objects are not always going to be available, depending on what point
of the report creation cycle we are at.
Removing Elements from a Report
The easiest way to drop elements from reports is to find the element using the
Design Handle's findElement method. This method will return a reference to a
DesignElementHandle, referencing the item whose name is used. Let's say we were
to change the name of the Data element with the test String Expression used earlier
in this chapter to dataElementToRemove. The following code will search the Report
Design, find the matching element, and remove it from the report.
Pages:
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200