Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
[ Script ] How to list library used in a report?
egau
Hello everyone,<br />
<br />
I'm interesting in getting library's name that are used in a report and save them in a table so I can re-use them later ( for theme management ) <br />
<br />
Do you know how could I do that ?<br />
<br />
It could look like something like that : <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
i = 0
themeTab = new Array();
while(i < reportContext.getDesignHandle().getNumberOfTheme){
themeTab[i] = reportContext.getDesignHandle().getTheme(i);
}
</pre>
<br />
So after that, when I want to modify a property of a library i just need to do:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportContext.getDesignHandle().findLibrary("myResources/"+themeTab[i]);</pre>
<br />
Any clue ?<br />
<br />
Thanks in advance.
Find more posts tagged with
Comments
mwilliams
Here is a script you can use that will step through your libraries and store the library paths to an array, that you can store in a global variable and access anywhere. Not the comment in the script that shows how you can just grab the name, instead of the path.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
i=0;
myLibraries = [];
lh = reportContext.getDesignHandle().getAllLibraries();
while (i < lh.size()){
myLibraries[i] = lh.get(i).fileName; //this returns the path to the file - property 'namespace' returns just the rptlibrary name
i++;
}
reportContext.setPersistentGlobalVariable("myLibraries",myLibraries);
</pre>
<br />
Hope this helps.
egau
It helped a lot, thanks !
egau
Hello again,
I have a question related to the findLibrary method.
When I don't defined the Resources path of my project, this works :
lh = reportContext.getDesignHandle().findLibrary("C:\Users\********\Desktop\Test%20BIRT\Theme\test\resources\theme.rptlibrary");
but when I define a specific resources path, like "<Current Project Folder>/resources"
it doesn't work anymore, do you know why ?
Thanks in advance.
Regards,
mwilliams
Try using 'namespace' in the above code, rather than 'fileName', then, you should just be able to find the library with something like:<br />
<br />
reportContext.getDesignHandle().findLibrary("resources/" + myLibraries
);<br />
<br />
This will work as long as your library is in a folder called resources in your workspace. This should be the path you'll see if you hover over the library in the report outline.
egau
Hello ! Thanks (laaaaaaaaaaaater ) <br />
<br />
Here is the complete solution:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>var i=0;
var myLibraries = [];
al = reportContext.getDesignHandle().getLibraries();
while (i < al.size()){
myLibraries[i] = al.get(i).getRelativeFileName();
i++;
}
lh = reportContext.getDesignHandle().findLibrary("design/Themes.rptlibrary");
th = lh.findTheme(params["theme"].value);
if (th != null)
reportContext.getDesignHandle().setProperty("theme",th);
i = 0;
while (myLibraries[i]){
lh2 = reportContext.getDesignHandle().findLibrary(myLibraries[i]);
lh3 = lh2.findLibrary("design/Themes.rptlibrary");
if (lh3 != null)
{
th2 = lh3.findTheme(params["theme"].value);
if (th2 != null)
lh2.setTheme(th2);
}
i++;
}</pre>
mwilliams
Awesome! Thanks for the update!