Wed, 2023-09-27 16:00

Hi all
is this possible and how ?
We'd like to give the end users a (possibly) permanent URL where they could retrieve the report output (which could be stored in Aris Connect Document Repository)
Thanks
PS : a javascript solution is OK as our report is not a wysiwyg report
Hi,
well, it should be possible, but a little bit complicated... just generate the output file, then get the ADS document (e.g. by link) and update the document there...
But "just" is - as I said - complicated :-)
Robert
Hi Robert
OK, let's assume I know how to get the report ouput content in my report
Looking at https://your_aris_server_/abs/help/en/script/ba/index.htm#report_OBJECTS_ADSReportComponent.htm
One could go along the following lines :
Well, there could be two ways:
1) directly when running the script
var oFile = Context.getFile(Context.getSelectedFile(), Constants.LOCATION_OUTPUT);
var oByteArrayInputStream = new java.io.ByteArrayInputStream(oFile);
var oInputStream = new java.io.BufferedInputStream(oByteArrayInputStream);
2) by usage of an second script that uses the report scheduler
var reportScheduler = Context.getComponent("ReportScheduler");
var aByteArrayResult =
reportScheduler.getDecryptedScheduleResult("scheduledReportGUID", "username", "password", false);
var aSelectedFile =
reportScheduler.getZipEntries(aByteArrayResult);
var aByteArrayXLSX = null;
for (var i in aSelectedFile) {
if (aSelectedFile[i].getName().equals("OutputFile.xlsx")) {
aByteArrayXLSX = aSelectedFile[i].getData();
break;
}
}
var outputFile = new java.io.File(filePath + "\\OutputFile.xlsx");
var fop = new java.io.FileOutputStream(outputFile);
if (!outputFile.exists()) {
outputFile.createNewFile();
}
fop.write(aByteArrayXLSX);
fop.flush();
fop.close();
Not quite sure if the second one works, but the first one should be usable anyway...
Robert
Thanks , I'll give it a try
I guess I'll have to write two scheduled reports
Why though? If you want to store something in the ARIS Document Storage, just store it in the ARIS Document storage.
I've written about this topic in this thread https://www.ariscommunity.com/users/nishabaste/2021-05-18-using-ads-through-aris-scripting#comment-27914 explaining how to retrieve and update ARIS Document Storage documents by report.
It boils down to
1. Write output file as if you'd want to send it to a client
2. Locate ADS Document with ADS Report Component Interface
3. Get output file as byte array with Context.getFile(...)
4. Create Java ByteArrayInputStream with byte array
5.give ByteArrayInputStream to ADS method which will use it to update the document
6. If you want to make sure nobody can use your report to get the file directly, wipe it from the output directory with Context.deleteFile(...)
Hi Kay
the use case is : schedule a report and make the output available in the ADS
Can this be done from within a scheduled report ?
Hello Michel,
Today I was hitting the same issue of uploading report output directly to ADS, not willing to have an intermediate step where the output is stored in a file on the server.
I succeeded in doing this and am happy to share with the ARIS Community. Fair to say is that I've been inspired by the file ADSUploader.js which can be found in the 'Reports/Dashboard data' folder. The folder structure (Dashboarding/<database name>/) is inspired by the ADSUploader.js. You can change this and all hard-coded variables to your needs.
All required code is inside the function. One can copy/paste the function into ones code and then call it like shown in the first code snippet.
The upload function:
A screenshot of the result in ADS is attached.
Best regards,
Harm
Ok ,thanks to Robert and Kay I managed to :
For those interested , the working code is just below.
However there is still something that bugs me.
The script works like this :
First question is : how to delete the unused file (the one created in setp one above) ?
Second question : how to avoid altogetther the creation of this temporary file ? Is there a function of the OutputObject that could be called to get the byte stream needed by the ADS functions ?
Thanks
Working code snipet :
No, calling writeReport() writes a file whose content previously only existed in Server RAM to a temporary output directory (on the server) that is specifically created for an instance of your report execution. It does nothing more - no file is passed to the client while the report is running.
After your report concludes there are two conditions for a file to be transfered to the client:
The file created in step one can be deleted with
In addition to deleting the file I also recommend that if you really don't want to transmit your file to any potential client you create your file with a different filename than the one provided by Context.getSelectedFile() (and adjust the first parameter of the Context.deleteFile(...) call). As I've written before, this file name is registered by default for output file transfer, therefore if you instead use something like "businessReport." + your file extension without registering this made up file name as an output file it would never be transfered to begin with. Also make sure to set the selected file with Context.setSelectedFile("noRealName.noRealExtension") to something that's not "businessReport." + your file extension. This prevents users from acquiring the file even if they were to manually set their output file name to "businessReport." + your file extension.
That I don't know. The ARIS OutputObject is most likely backed by different libraries depending on the output format (e.g. Apache POI if you create a docx Document, ...) and I doubt there is a universal method to tell all those different libraries to output into a buffer instead of writing a file to the filesystem.
Hm, I think if you set "Context.setScriptError(Constants.ERR_NOFILECREATED);" no file is sent to the Client when the script is finished...
Yes, solution (1) :-)
Hm, you just don't use the WriteReport (as this moves the file to the end user), but grab the file from the temporary folder on the ARIS server instead...
If I find an example, I will post it...
Thanks all @Robert Goldenblaum and @Kay Fischbach
For the record below a code snippet that achieves the desired result