# Creating Delegate class dynamically

**URL:** <https://forum.flowable.org/t/creating-delegate-class-dynamically/7716>\
**Category:** Flowable Engine\
**Created:** [April 9, 2021, 6:17am UTC](https://forum.flowable.org/t/creating-delegate-class-dynamically/7716 "2021-04-09T06:17:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jyothsnal](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jyothsnal](https://forum.flowable.org/u/jyothsnal)\
**Post date:** [April 9, 2021, 6:17am UTC](https://forum.flowable.org/t/creating-delegate-class-dynamically/7716/1 "2021-04-09T06:17:21Z")

</div>

Hi my requirement is I need to create BPMN Model dynamically. I’m able to create the BPMN Model which contains service tasks and exclusive gateways. Is it possible to create delegate classes which we give for each service task for example : ${ruleOneTask} dynamically. Here ruleOneTask class should be created at runtime.

Can anyone help me on this

---

<div class="post-metadata">

**Author:** ![jwashington](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jwashington](https://forum.flowable.org/u/jwashington)\
**Post date:** [April 9, 2021, 6:17pm UTC](https://forum.flowable.org/t/creating-delegate-class-dynamically/7716/2 "2021-04-09T18:17:14Z")

</div>

This question is fairly complex so let’s try to break it down a little. The delegate expression ${ruleOneTask} is evaluated by Flowable’s expression expression manager to resolve a variable named “ruleOneTask” into a delegate instance for the service task. In the Spring boot world, you would normally create a delegate bean named “ruleOneTask”. Since you want to dynamically control the delegate instance, you have a few choices. One possibility is to dynamically create appropriately named Spring beans matching the name in your delegate expression. Another possibility is to override the Flowable expression manager to control how delegate instances are resolved and incorporate your own custom logic. For Spring boot, you could subclass the SpringExpressionManager class to add your own logic and set the expression manager in your configuration. The question of how to dynamically create delegate is really up to you.

---

<div class="post-metadata">

**Author:** ![jyothsnal](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jyothsnal](https://forum.flowable.org/u/jyothsnal)\
**Post date:** [April 16, 2021, 6:24am UTC](https://forum.flowable.org/t/creating-delegate-class-dynamically/7716/3 "2021-04-16T06:24:13Z")

</div>

Thank you for the reply.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [April 20, 2021, 6:24am UTC](https://forum.flowable.org/t/creating-delegate-class-dynamically/7716/4 "2021-04-20T06:24:08Z")

</div>

To add to what @jwashington,

When using a delegate expression nothing is stopping you to use `${ruleOneTaskCreator.createDelegate()}`. You can pass parameters etc to it. The important part is the method to return back `JavaDelegate`.

Cheers,  
Filip
