Customize Service Task in Process Engine

This is a process engine question. I’ll figure out eventually how to add a custom task element to my editor palette etc, but I’m not sure how the process will react when I try to deploy the process with customized service task.

I want to create a service task with all form properties that a user task has. The difference will be that this task will not wait for user to react, just generate a form (not asking how to do it for now), store it in a variable and move on, all in the same transaction, like a service task.

I’m guessing I have to extend some of task classes, either user or service, register it with the engine, so that it is not surprised at deploy time when there are some unexpected properties, and the Java delegate will have access to the form definition properties. Or should I not extend anything, if bpmn XML has any property, the delegate will be able to see everything even if the properties are neither in bpmn nor camunda namespace.

So I’m asking for some general advice, hope I was clear:slight_smile: Thanks!

What’s your use case ?

There is a need of a service that will provide form fragments. It will be good if it is defined in bpmn file in the same manner as regular forms. The other way I see is to pass arguments to the java method (the one that’ll be called in the service task), but it’s not that intuitive

Can you be more specific about your use case? Your initial description sounds like you want to have all of the fields of the user task but pre populate them with essentially a script and store the values. Why do you think you need customized service tasks and modeler changes for your use case?

Right out of the box you could use input variables on a service task to replicate each of the form fields or you could use modeler element templates to provide a more custom form in the modeler. https://docs.camunda.org/manual/7.8/modeler/camunda-modeler/element-templates/

And then you can process your data into a process variable (Json or java object).

Well, I want extend a service task definition element with the form definition structure, like we currently have in user task or start event elements. The service will generate the form (html) and, say, store it in the process variable. Are you asking why I need this and assume I might actually don’t? :slight_smile: I really wouldn’t like to disclose the idea prematurely. Eventually I will. I understand that I gave too much detail for what is really a simple technical question. If you don’t mind, can I rephrase it to some more generic one:

How do I add my own property to a [serviceTask], like you added camunda:expression property, but my own, and do nothing more then make it available to the ‘java delegate’.

I saw you edited your post, now reading that, thanks!

If it’s impossible what I’m asking (wihtout, like, forking Camunda ;), it’s okay, I’ll propably employ the input variables or something, thank you!

I am asking about your use case because it seems like you are developing a solution to technical problem that does not exist.

So short version: you want to generate some HTML and store it in a process variable. And that HTML would include some values in a form in the modeler? If yes, look at the element templates. You can easily script this or use java delegates to generate the process variable.

@StephenOTT, I am writing my own properties editor (not using the ‘panels’ that have element templates), look:

I was thinking to learn how to create my own namespace (like, fedd:formKey ) / moddle etc, my question is how the service task will see my new property

And that HTML would include some values in a form in the modeler?

eer, not really. That HTML will be defined by the values in some [scriptTask] properties. For example:

<serviceTask  id="formService"
         name="My Form Service Task"
         camunda:class="org.fedd.GenerateForm"
         camunda:resultVariable="aForm" >
  <extensionElements>
    <fedd:formData>
        <fedd:formField
            id="firstname" label="Firstname" type="string">
        </fedd:formField>
        <fedd:formField
            id="lastname" label="Lastname" type="string">
        </fedd:formField>
        <fedd:formField
            id="dateOfBirth" label="Date of Birth" type="date" />
    </fedd:formData>
  </extensionElements>
</serviceTask>

When executed, it’ll create an HTML

Okay thanks for the context. That clears it up :+1:t2:
When you send your properties into the task, Have you tried submitting them as input variables? Then you can use script or delegate to process them. IMO Would save you a lot of hassle compared to working with a new namespace, parsing the bpmn XML, or camunda extension properties. The input vars already give you so much control with out of box features

1 Like

In a service task you can use the method DelegateExecution#getBpmnModelElementInstance which returns an instance of org.camunda.bpm.model.bpmn.instance.FlowElement which allows you to access any elements and attributes defined in the XML.

1 Like

@StephenOTT, i will do that if I fail with ext properties. I need it just for sake of intuitiveness of bpmn file editing.

@thorben, thank you, I will investigate this!

you guys are real. a big difference how activiti/flowable people react to my crazy demands :wink:

1 Like