Hi all,
I'm making a report which runs on a group and its subgroups hierarchy and models. Each model should be saved in a separate file, residing in a directory reflecting the subgroup, where it is located. For example, if the model is located in Group1\Group2\My Model, then the report should be saved in a file ${user.selected.dir}\Group1\Group2\My Model.xml (${user.selected.dir} is the directory, selected by the user when the report was run).
What I managed to dig-out from the documentation is method Context.setSelectedPath(), but it doesn't seem to work. Here is the code:
// Get the current group and all its children var group = ArisData.getSelectedGroups()[0]; var groups = group.Childs(true); for (var i=0; i<groups.length; i++) { // Iterate over group's models var models = groups[i].ModelList(); for (var j=0; j<models.length; j++) { // Create the report var doc = createXMLDocument(models[j]); // Get the absolute path of the directory, where the report should be saved. // getAbsoluteOutputPath () is a local function which concatenats // Context.getSelectedPath() and the group path. The path separators are // converted from '\' to '/'. var path = getAbsoluteOutputPath(models[j]); // Set the output path Context.setSelectedPath(path); // Get file name var xmlFile = models[j].Name(nLocale)+".xml"; // Get XML writer and write the report var xmlWriter = Context.createXMLOutputObject(xmlFile, doc); xmlWriter.WriteReport(); } }
However invoking
Context.setSelectedPath(path);
results in saving all files in ${user.home} directory (e.g. C:\Users\simeon\Documents\BPA11) instead of ${user.selected.dir} without creating any subdirectory structure.
Thank you for your help!
Simeon
Never mind, it seems that it is not possible to create this kind of directory structure on the client computer. So, I tried different approach - I'm generating the files on the server and I'm saving them under Context.getTempPath() directory.
Then I ZIP them into single archive and I get the ZIP at the client with Dialogs.shell(). The ZIP file is opened on the client's computer, but the afterwards the Dialogs.shell() method gives error:
"Script: , line -1"
Are there any known issues about Dialogs.shell() method?
Simeon
Hi Vladimir and thank you for your response.
Dialogs.shell() code is in the report. The reports API ptovides access to Dialogs, so it is possible to collect additional information, show messages, etc.
Yes, I get "Script: , line -1" only in editor, but if I run the report in Explorer the BPA client hangs and has to be restarted forcefully. I posted more detailed article about this in Aris Support Group: http://www.ariscommunity.com/users/skirov/2012-01-09-report-script-bug-dialogsshell
Hi Simeon,
You could initiate the report from a macro. In the macro you determine which models need to be exported, you create the output dir and run the report for only the selected models in one group. This wil result in output to the wanted directory.
Best regards,
Edwin
Hi Simeon,
There are two methods for saving the files to some specific folders on server. I am explaining one of it. You need to find out how to bring those files to client machine. There can be many ways to bring the files on client machine, you can take help of Macros also by setting the return Property from report. Or through any other desktop app.
I am considering that you have JDom Document object, returned by your method
var doc = createXMLDocument(models[j]);
Here after this you can do the following steps
1. Import file "convertertools.js" in script from Script properties.
2. Use the followin code to save it to specific location
var l_XMLOutputter = org.jdom.output.XMLOutputter(); __createDirectory("C:\\Group1\\Group2"); var l_FileOutputStream = java.io.FileOutputStream("C:\\Group1\\Group2\\test.xml"); l_XMLOutputter.output(doc, l_FileOutputStream); l_FileOutputStream.close();
The other way is to create files using Java File writer, writing simple text files with XML tags in it, if the XMLs you are generating are in the custom format.
Regards,
Amol Patil