I have a report (output is .doc), and at the end of its output file I want to display contents of other file(.doc), that is stored on a server.
Which function does this and how?
Hi Misha,
using the latest service release (SR03 / 2012), you can read a stored doc file and insert it into another output document.
Create your output document using our new output object: Context.setProperty("use-new-output", true) var output = Context.createOutputObject() ...write something into output object or jump to a mergefield
You can read a document (.doc) using
Context.getOutputObject("any name ending with .doc", byte[] (the file content))
...returning an "ExtendedOutputObject". Example:
var docToInsert = Context.getFile("storedDocument.doc", Constants.LOCATION_SCRIPT) var myOutputObjToInsert = Context.getOutputObject("whatever.doc", docToInsert)
Insert it into your output document:
output.InsertDocument(myOutputObjToInsert, false, false) output.WriteReport() //finish
Best regards,
Torsten
Hi Torsten,
I have two questions:
1.
I'm on 7.2.3.631018, the code I try is as follows:
var oOutput = Context.createOutputObject() ..... var aFile = Context.getFile("file.docx", Constants.LOCATION_COMMON_FILES) var oObj = Context.getOutputObject("BRD-ARIS.doc", aFile) oOutput.InsertDocument(oObj, false, false) oOutput.WriteReport() Error message I got is "Cannot find function InsertDocument in object OutputObject XXXXX..." What can be the problem? Any library missing?
2.
How to convert user-defined path into a valid parameter for getFile?
Regards,
Nikolai
Thanks for replay ! I learned muuch from your post .
Now I want to copy one file to another directory , and I couldn't do it. Can you give me hint ?
For example I have file D:\a.doc and I want to have it on C:\ how can I do that ? I tried to do it with Java library , but
new java.io.FileOutputStream("D:/a");
says :
Wrapped java.io.FileNotFoundException: D:\a.doc (The device is not ready) |
the same is with new java.io.FileInputStream(f);
Is there in ARIS API functions to copy a file ?
P.S. wich version of java libraries is used in ARIS SCRIPT ?
Thanks a lot
Hi Misha,
the java library version is the same that is used by the rest of the server. Should be at least 1.5.
Be very careful when dealing with files in a report, because a report is executed on the server side. This is your local machine only in LOCAL or localhost scenario. In the 'normal' case of use you use a remote server and you cannot know the file system structure or user permissions on the server. This may lead to the described error.
BR,
Torsten
Thanks Mr. Torsten Haase, now I know the reason of the error. There is no other solution, I have to copy files to local machine... Can you tell me how to copy them on local machine and not to Server ?
Hi Nikolai,
1) You make use of the extended output object here. In order to make "createOutputObject" create an extended output object, you have to insert the following line before calling "createOutputObject" until the extended output object becomes the standard:
Context.setProperty("use-new-output", true)
2) you should avoid direct access to the file system in report scripts, so the best way is to have your "template file" "BRD-ARIS.doc" stored either in the report script's category or in "Common Files".
Best regards,
Torsten
Hi Torsten,
many thanks for clarification on first issue.
Regarding the second one:
a. What is the problem getting file form the file system and inserting it into the ARIS report? Is there way to do it sourcing file path from AT_EXT_1 attribute or from user dialog?
b. Can I source binary object from AT_DOCUMENTATION? What would be the correct syntax for this insertion?
Thanks and Regards,
Nikolai
Hi Torsten,
Fully agree to your statement that you should prevent direct access to the file system, but in some cases it's necessary. I have used an xml input to be combined with ARIS content, and the report had to run scheduled, so I had no option but directly access the filesystem.
Best regards,
Edwin
Hi Nikolai,
a.1) the problem would occur when you use ARIS in a multi-server scenario. In this case you cannot determine, from which server's file system the file would be read.
a.2) using AT_EXT_1 would not help much, because it contains only a file system link which would cause the same issue as (a.1)
a.3) using a user dialog you can browse the client's file system. The function Dialogs.getFilePath returns the file content, which can be processed by your report
b) Yes, you can access the content of AT_DOCUMENTATION from the report easily. The following piece of code shows you how:
var attrDoc = obj.Attribute(Constants.AT_DOCUMENTATION,Context.getSelectedLanguage()); if(attrDoc.IsMaintained()){ var bytearray = attrDoc.getExternalDocument().getDocument(); var docVal = Context.getOutputObject("tmp.doc",bytearray); // this would insert the AT_DOCUMENTATION content into another document: mainOutputObject.InsertDocument(docVal,false,false); // this potentially saves memory: docVal = null; }
Best regards,
Torsten
Thanks Torsten, You're star.
I'm still looking for option to source file using path. We have common shared drives and SharePoint so multi -server ARIS environment should not be a problem.
Dialog option definitely works, but in my case I can provide fixed link in AT_EXT_1. Is there way to get file from this location ( not predefined in Constants) not using dialog? May be I can suppress dialog somehow?
Developing the topic I have some more questions:
1. What is the use of "Parameter X" attribute for Link X?
2. How to make script to write into existing doc file. I mean having doc template with tags which will be replaced with information from ARIS.
Thanks.
Nikolai
Hi,
var docToInsert = Context.getFile("ProcedureReport.doc", Constants.LOCATION_SCRIPT)
var myOutputObjToInsert = Context.getOutputObject("tmp.doc", docToInsert)
oOutput.InsertDocument(myOutputObjToInsert, false, false)
oOutput.WriteReport()
But I am getting an error "Cannot create output object.Cannot create document"
Kindly need your help to understand where I have gone wrong?
Regards,
Kaushik