Fetching an attached file programmatically in business process

cancel
Showing results for 
Search instead for 
Did you mean: 
ta
Member II

Fetching an attached file programmatically in business process

Hello,

I've tried to programmatically find and read file that was attached to business process. The process contains a form attached to star event including file attachment form field. When the process is started, the user will upload a file using the form.

 

I'd like to read and manipulate that file in a script task later in the process but cannot find a suitable method for reading the file.

I've tried so far:

  • relatedContentService.getRelatedContentForProcessInstance(execution.getProcessInstanceId(), pageSize, pageNumber)
  • taskService.getAttachment('filename')
  • execution.getAttachment('filename')

All of the above return null values. Is there some other method for reading/listing attached files?

Thanks in advance!

1 Reply
abbask01
Senior Member

Re: Fetching an attached file programmatically in business process

You can also fetch the content by the process variable name with the below code

relatedContentService.getFieldContentForProcessInstance(
               execution.getProcessInstanceId(), VARIABLE_NAME, 1, 0).getContent();

 Have a look at this tutorial - https://hub.alfresco.com/t5/alfresco-process-services/getting-started-with-alfresco-process-services...

Also the other 2 methods you mentioned works with attachment I'd which is different from filename

Regards,
Abbas