Working with attachment fields in Script task

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

Working with attachment fields in Script task

I am attempting to work with files that have been attached in a form. How would I go about retrieving information within a JavaScript Script task? When I do a /activiti-app/api/enterprise/process-instances/${process_instance_id} call, I see that my variable for the attachment field = null, even when I have attached a document there. 

I'm aware there is a relatedContentService, which requires some dependencies. Is there any way to check information (ANY information) on an attachment without leaving the BPMN editor?

Thank you

8 Replies
Highlighted
Active Member II

Re: Working with attachment fields in Script task

Greer Banks‌ you need to use bpm_package in this way:

<code> var documents = bpm_package.children; </code>

Then you can loop through it to get those documents.

Highlighted
Active Member II

Re: Working with attachment fields in Script task

So I would still need to loop through the documents without being able to use it's ID from the form field? Because I can perform an api call to do the same thing, the issue is that documents are coming in in different orders based on what is attached.

Highlighted
Master

Re: Working with attachment fields in Script task

The reply by ‌ is only valid for the Alfresco Content Services embedded Activiti runtime. It is not valid for the Alfresco Process Services runtime.

Highlighted
Active Member II

Re: Working with attachment fields in Script task

‌ yes you have to still loop through. Even in the bpm_package the order is not necessarily as attached by the users. I do not think you can use the document IDs from the form field directly in a workflow start page without having started the process. As the process goes, the documents attached are still "soft-links" and have no relation yet with the process at that stage; only when the process has successfully started do the documents have the workflow metadata attached to them.

Hope this explanation is helpful.

Happy coding.

Highlighted
Active Member II

Re: Working with attachment fields in Script task

The process would have been started by then. How can I access the metadata of the attachment form fields within a JavaScript?

Highlighted
Active Member II

Re: Working with attachment fields in Script task

What would I do then in the Alfresco Process Services runtime?

Highlighted
Master

Re: Working with attachment fields in Script task

I am currently on vacation without access to the sources of the Alfresco Process Services project I am working on for one of my customers, so I cannot check if/how we dealt with that within scripts. I'd have to check how it is possible to access the Spring application context from withiin a script - with that you could access every Java services from scripts. I do this within Alfresco Content Services all the time and it's quite easy there via some static utilities, but have not had the need to do this with Process Services yet.

Last time I had to deal with related content (~4 weeks ago), I opted to write a Java-backed delegate since my delegate was intended to be reused in many process definitions (scripts or specifically script management in Process Services sucks with regards to reuse + testability).

Active Member II

Re: Working with attachment fields in Script task

When/if you are able, could you please provide an example where you were able to perform something like this within a Process Services script/listener? Thank you for your insight, Axel.