How to get a document of one process and show it in other process?

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

How to get a document of one process and show it in other process?

Hi,
I need to recuperate a document from one process and show this document in other form of other process.

I have two process:

This is the first process with the document. It call to 'activiti call'.

The second process need to recuperate the document and show it in the form:

With Java i can recuperate the document object but i can't put it in the second process:

@Autowired
    FormService formService;        
@Autowired
RelatedContentService relatedContentService;

@Override
    public void execute(DelegateExecution execution) throws Exception {
        System.out.println("*******************  RetieveAttachment  *******************" );
        
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        TaskService taskService = processEngine.getTaskService();        
        
         List<RelatedContent> contentList = relatedContentService.getFieldContentForProcessInstance(execution.getVariable("varGlo_idProceso").toString(), "form_scfhq_marcos_ini_englishframeworkversion", 1, 0).getContent();

//Show results

 if (contentList != null) {

               for (RelatedContent relCon : contentList) {
                   System.out.println("Content file: " + relCon.getName() + ", created: " + relCon.getCreated());
                   ContentObject co = relatedContentService.getContentStorage().getContentObject(relCon.getContentStoreId());
               }
        }
        
    }

Can anyone help me?

regards,
David
3 Replies
afaust
Master

Re: How to get a document of one process and show it in other process?

I implemented something in that direction for a customer of mine this year. This was required for passing a document from one process into another (child). For that I developed an execution listener in the child process that would use the process instance ID (and other parameters) provided by the parent process via variable mapping, look up the related contents and re-create them for itself.

The RelatedContentService and RelatedContentStreamProvider is all you should need for this. You look up the document via the related content service (like you already do), obtain its stream from the stream provider, and can then create a new related content again via the related content service. Once stored in as a related content for another process you can then show it in a form of that process with the typical attachment form field.

deivid
Member II

Re: How to get a document of one process and show it in other process?

Hi Axel,
Thank you, it works whit this code:

@Component
public class RetieveAttachment implements JavaDelegate {

    @Autowired
    UserService userService;

    @Autowired
    RelatedContentService relatedContentService;

    @Autowired
    RelatedContentStreamProvider relatedContentStreamProvider;

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        System.out.println("*******************  RetieveAttachment  *******************");

        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        User user = userService.findUser(Long.parseLong("1"));
        System.out.println("Usuario: " + user.getFullName());

        // Look up the document via the related content service
        List<RelatedContent> contentList = relatedContentService
                .getFieldContentForProcessInstance(execution.getVariable("varGlo_idProceso").toString(),
                        "form_scfhq_marcos_ini_englishframeworkversion", 1, 0)
                .getContent();
        ContentObject contentObject = null;
        InputStream inputStreamContent = null;

        if (contentList != null) {
            for (RelatedContent relCon : contentList) {
                System.out.println("Content file: " + relCon.getName() + ", created: " + relCon.getCreated());
                contentObject = relatedContentService.getContentStorage().getContentObject(relCon.getContentStoreId());

                // Obtain its stream from the stream provider
                inputStreamContent = relatedContentStreamProvider.getContentStream(relCon);

                // Create a new related content again via the related content service
                relatedContentService.setContentField(relCon.getId(), "attachment", execution.getProcessInstanceId(), null, true);

            }
        }

    }

}

On the other hand, I would like to show the document and can download from the form.

I can see it in my form:

But i need download this document for work about it.

I configured the field form like 'Attach' with this properties:

Could you help me?

regards,
David

afaust
Master

Re: How to get a document of one process and show it in other process?

I am not sure that code is really the best choice. Have you tried deleting the attachment in the parent process? How does it relate to the attachment in the project where it was copied to? We had several issues with the whole attachment management (which is really awkward) which is why I opted to fully copy the attachment (as in "duplicate it") instead of just linking it in my field as you have done.

With regards to the download question - I am not sure what would affect this, for us it did "just work". BTW: We are using 1.6.0, so maybe you have a different / older version that I am not as familiar with.