Form uploaded via REST api is not getting loaded in tasklist

Hi

I deployed a bpmn file along with a form using REST api.

Here is my code.

File file = new File("C:\\Users\\prasad\\Desktop\\camunda-get-started-Step-4\\src\\main\\resources\\loan-approval.bpmn");
        FileSystemResource bpmnFileResource = new FileSystemResource(file);
        File formFile = new File("C:\\Users\\prasad\\Desktop\\camunda-get-started-Step-4\\src\\main\\webapp\\forms\\approve-loan.html");
        FileSystemResource formFileResource1 = new FileSystemResource(formFile);
        File formFile2 = new File("C:\\Users\\prasad\\Desktop\\camunda-get-started-Step-4\\src\\main\\webapp\\forms\\request-loan.html");
        FileSystemResource formFileResource2 = new FileSystemResource(formFile2);
        MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
        parts.add("deployment-name", "loan-approval-form");
        parts.add("enable-duplicate-filtering","true");
        parts.add("deployment-source","process application");
        parts.add("loan-approval.bpmn",bpmnFileResource);
        parts.add("approve-loan.html", formFileResource1);
        parts.add("request-loan.html", formFileResource2);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<MultiValueMap<String, Object>>(parts, headers);
        ResponseEntity<DeploymentResponse> response = restTemplate.exchange(deployURL, HttpMethod.POST, request,DeploymentResponse.class);

The files are deployed successfully and I am getting the deployment Id as well as the resource Id for these items(bpmn files and fom files).

However while clicking on start process button in tasklist it shows only loading

Here is my bpmn file

<bpmn:process id="approve-loan" name="Loan Approval" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1" name="Loan Request Received" camunda:formKey="embedded:app:request-loan.html">
      <bpmn:outgoing>SequenceFlow_0c4zr6d</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="SequenceFlow_0c4zr6d" sourceRef="StartEvent_1" targetRef="UserTask_11fud4o" />
    <bpmn:userTask id="UserTask_11fud4o" name="Approve Loan" camunda:formKey="embedded:app:approve-loan.html" camunda:assignee="john">
      <bpmn:incoming>SequenceFlow_0c4zr6d</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1y4c0rn</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:endEvent id="EndEvent_1i5bz86" name="Loan Request Approved">
      <bpmn:incoming>SequenceFlow_1y4c0rn</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="SequenceFlow_1y4c0rn" sourceRef="UserTask_11fud4o" targetRef="EndEvent_1i5bz86" />
  </bpmn:process>

These are the REST calls I got from the tomcat log file. When I pasted in the browser I got the following response

  1. http://localhost:8080/engine-rest/engine/default/process-definition/approve-loan:1:70e10ed5-25b3-11e6-8eb8-386077505d14/startForm

{“key”:“embedded:app:request-loan.html”,“contextPath”:null}

  1. http://localhost:8080/camunda/api/engine/engine/default/process-definition/approve-loan:1:70e10ed5-25b3-11e6-8eb8-386077505d14/startForm

{“key”:“embedded:app:request-loan.html”,“contextPath”:null}

Does my process engine aware of the form registrations
I deployed along with the bpmn file ??? … therefore not able to resolve the context path to your form…How can I deploy these form files with REST API…please help me out

1 Like

Hi Prasad,

probably the problem is the wrong form key in the user task.
Please change the usertask formkey from:

`camunda:formKey="embedded:app:approve-loan.html"`

into this:

`camunda:formKey="embedded:deployment:approve-loan.html"`

Please test the change with the new version of camunda (7.5) and give us feedback.

Thank you and greetings,
Christopher Zell

1 Like

@Zelldon The docs use the /forms/ path in the form key. This an out of date doc? Or can we create folders through Rest Deployment?

I have tried this embedded:deployment:TEST_FORM.html

where the deployment shows like this:
/Users/brent.fisher/work/intapi-payment-process-manager/server/build/resources/main/forms
TEST_FORM.html

I deployed it from code:
springProcessEngineConfiguration.setCreateIncidentOnFailedJobEnabled(true)
Resource[] resources = [
new ClassPathResource(‘bpmn-diagrams/EarlyPaymentProcess.bpmn’),
new ClassPathResource(‘bpmn-diagrams/PaymentBatchProcess.bpmn’),
new ClassPathResource(‘bpmn-diagrams/PrivateBankResponseProcess.bpmn’),
new ClassPathResource(‘bpmn-diagrams/TestProcessUI.bpmn’),
new ClassPathResource(‘forms/TEST_FORM.html’),
]
springProcessEngineConfiguration.setDeploymentResources(resources)

unfortunately, the task list isn’t able to load it here either:
" Form failure: Resource TEST_FORM.html not found in deployment"

Hi @pescador_bob,

I think, it should look like this: embedded:deployment:forms/TEST_FORM.html.

Could you try this out?

Cheers,
Roman

Yeah, actually, that’s what the documentation says. I’ve tried many
permutations, but unsuccessfully. Here are the permutations I have tried:
embedded:deployment:forms/TEST_FORM.html
deployment:TEST_FORM.html
TEST_FORM.html
embedded:deployment:TEST_FORM.html
embedded:deployment:TEST_FORM

I am running with the cockpit and my app in separate jvms though, so maybe
that prevents this from working correctly. I have the cockpit running in
the cockpit docker image, and my app running in a separate jvm, but they
both share the same db.

@pescador_bob does it work if you upload the form through the rest API?

see the following for code example:

https://medium.com/@stephenrussett/deploying-embedded-forms-with-camunda-rest-api-84cf8010f8c1#.21pw5lazi

[image: pasted1]

It shows the form is deployed as a resource, but I just can’t quite access
it from the bpm.
[image: pasted2]

One noticeable difference is that it doesn’t show the name of the deployed
resource as forms/TEST_FORM.html, but TEST_FORM.html

All of the tries gave me this:
[image: pasted3]

interestingly enough, if I specify it like this:
embedded:deployment:/Users/brent.fisher/work/intapi-payment-process-manager/server/build/resources/main/forms/TEST_FORM.html

then I see the expected:
[image: pasted4]

@pescador_bob Can you repost the images through the form? Images did not upload over email.

Thanks for your reply StephenOTT. I don’t really want to use the REST api right now as I have the engine embedded. Perhaps there is a better thread for me to post on though, since this thread is all about REST. Sorry that my images didn’t come through. That’s too bad. A picture is worth a thousand words, and that would be very handy!
Here is a second try with the pictures.

It shows the form is deployed as a resource, but I just can’t quite access
it from the bpm.

One noticeable difference is that it doesn’t show the name of the deployed
resource as forms/TEST_FORM.html, but TEST_FORM.html

All of the tries gave me this:

interestingly enough, if I use embedded:deployment:/Users/brent.fisher/work/intapi-payment-process-manager/server/build/resources/main/forms/TEST_FORM.html as the Form Key, then the form displays correctly:

I could be wrong… But if you are using embedded engine, i thought to call the forms was to use:

embedded:app:start-form.html

or possibly? embedded:app:forms/start-form.html

similar to: https://github.com/camunda/camunda-bpm-examples/tree/master/usertask/task-form-embedded

but I am not using app, I am using a deployed form. However, here is an answer. If I deploy it like this:
new DefaultResourceLoader().getResource('forms/TEST_FORM.html'),

instead of this:

new ClassPathResource('forms/TEST_FORM.html')

then the deployment looks right and works:

I hope that might help someone.

Hi @pescador_bob,

The name of a deployment resource becomes the absolute file path if you deploy it via SpringProcessEngineConfiguration as a class path resource (see https://github.com/camunda/camunda-bpm-platform/blob/7.6.0/engine-spring/src/main/java/org/camunda/bpm/engine/spring/SpringProcessEngineConfiguration.java#L108-L150 for the relevant code). We could change the auto-deployment behavior of class path resources to use the relative class path name only. However, I am a little bit reluctant to do that for reasons of backwards compatibility and breaking existing applications.

There are also plenty of workarounds: Do not deploy your processes via the auto-deployment function of SpringProcessEngineConfiguration, but for example via Java API (see RepositoryService#createDeployment), as part of a process application, or via REST API as @StephenOTT suggest. Let me know if you need help with that.

Cheers,
Thorben

1 Like

This is Good to know info!! Thanks @thorben!

Note that I was able to get it to work using the spring defaultResourceLoader.

2 Likes