Scripting with file attachments
If You want to evaluate a job's file attachment (e.g. save it to the file system, send it via email, upload it to some remote system, ...) please follow these instructions.
If you try to access the tickets' file attachments like this
var atts = task.attachments.toArray();
You will get a list of "proxy" objects which replace the real files as long as their content is not needed.
You might check this list and read the filenames of each attachment but when it comes to accessing the file's byte content you will need the following code to load the attachment from the database:
Please note the line
helper.getComponentStore().getEntityManager().find(com.proxemo.todo4.bom.ToDoAttachment.class, att.attachmentId);
which loads the real attachment of type com.proxemo.todo4.bom.ToDoAttachment.
The following script will look for an attachment with filename desired.xlsx in the list of attachments of the current task and load that attachment:
if(atts!=null){
println("Listing attachments!");
println("Number of attachments:" + atts.length);
for(var ai=0; ai<atts.length; ai++){
var att = atts[ai];
println("Attachment name: " + att.getAttachmentName());
if(att.getAttachmentName().equals("desired.xlsx")){
var attX = helper.getComponentStore().getEntityManager().find(com.proxemo.todo4.bom.ToDoAttachment.class, att.attachmentId);
println("Attachments' real size: " +attX.getAttachmentContent().length);
// do something with attX.getAttachmentContent()
// ...
}
}
} else {
println("No attachments.");
}