cancel
Showing results for 
Search instead for 
Did you mean: 

Expression input property in custom task

jbrazil5
Champ in-the-making
Champ in-the-making
I am building a library of custom tasks that will be imported into Activiti Designer. I have been able to follow along with the user guide and everything is working so far. However, I want to have a property where the user defines an expression as input to the custom task. There doesn't seem to be a way to do this. In the designer you can add a service task and then add fields with either a string or an expression, but in the @Property annotation there is no PropertyType.EXPRESSION, so a user of my custom task can't define an expression as input.

Am I doing this incorrectly? or is this functionality not available in extensions yet?

Thanks for the help!
7 REPLIES 7

jbrazil5
Champ in-the-making
Champ in-the-making
Nobody knows anything about this?

Maybe i'll try to rephrase my question.

What I would like to do is build a custom Activiti Designer shape, like from this example : http://www.activiti.org/userguide/index.html#eclipseDesignerExtending

In the example you can extend the Activiti Designer with your own custom shapes. This works fine. However, you can only create shapes that have constants as input(text,multi-line text..etc) OR pre-define an expression. In a normal service task you can define fields that have EITHER a string value as input OR an expression. I would like this same functionality but in my custom shapes. The ideal output would be when I add one of my custom shapes to the canvas it has a pre-populated list of input fields, and for each field I can either set a contant or define an expression.

Is this possible? Or do I need to look at building in this functionality myself?

I hope this clarification helps.

Please help!

Thank you!

tiesebarrell
Champ in-the-making
Champ in-the-making
jbrazil5,

I'm not sure I understand your question exactly. I assume you want to allow the modeller to use some kind of an expression in the property field of a CustomServiceTask. So, let's say that you have a text field and you want them to be able to use a process variable in the value, ${commentAddedByReviewer}, or whatever else. AFAIK, you are already able to do this, by making sure your @Runtime class has an Expression instead of a String member for the property. The userguide describes this as follows:

Note that since version 5.11.0 of the Designer you can use the Expression interface for dynamic field values. This means that the value of the property in the Activiti Designer must contain an expression and this expression will then be injected into an Expression property in the JavaDelegate implementation class.

Maybe this is not what you mean, so please explain if I misunderstood.

As for your ideal scenario:
The ideal output would be when I add one of my custom shapes to the canvas it has a pre-populated list of input fields, and for each field I can either set a contant or define an expression.

I don't understand what you mean by this. The input fields are pre-populated, with the default values defined for the CustomServiceTask. Or do you mean a list field (combobox) that gets the values somehow dynamically (not supported)? How do you "set a constant" when you're in editing mode for a process, which has nothing to do with constants?

jbrazil5
Champ in-the-making
Champ in-the-making
First off, thanks so much for answering! Sorry if I didn't explain it well.

I understand you can put an expression in the @Runtime annotation. In your explanation and in the documentation it seems like you need to know the expression you want to use before hand. I want the user to be able to put in an expression for a field from the designer, but also have the ability to use a string value  for a field if they want. Basically I want my custom tasks to have to same ability as the provided Service Tasks. You can add a field with either a String value OR set the expression for the field, but I want to have a pre-defined field name set.

For example I want to have a custom task with the following fields(Keep in mind sometimes the values might be a string and sometimes they might need to be a process variable) :

Field Name | String Value                   | Expression
username   | MyUsername                  | ________________
password   |______________                 | ${passwprdProcessVar}
domain      | http://www.google.com | _______________

I could create a Service Task and then set the service class to my custom class which implements JavaDelgate and has 3 Expression member variables(username, password, domain). Then lets say I want to use the same JavaDelegate over again in 5 different processes. I would have to create a Service Task , re-add those 3 fields(again, for each 5 processes) , and set the service class. This is really time consuming and redundant.

The great thing about the provided service tasks is that for each of those 3 fields I can either set the field to be an expression of my choice OR a string value. I would like this same functionality but for a custom task with those 3 field names pre-defined so that I do not have to create the 3 fields and set the service class every time. I think this is what extending the Activiti Designer should be able to help me out with , but so far it seems as though I can only create a field(@Property) with one of your pre-defined types (PropertyType.TEXT, PropertyType.DATE etc…) OR set an expression, not give the user the ability to select which one he wants it to be during process creation.

So sorry if I am not explaining this well, I am really new to using Activiti. I really appreciate your help!

tiesebarrell
Champ in-the-making
Champ in-the-making
I think the discussion is about two separate things, because you refer to both.

1) The class invoked when the process reaches the node at runtime. This is defined once, in the CustomServiceTask definition by specifying the @Runtime annotation.
2) The value of properties of an instance of the CustomServiceTask. The metainfo for the properties is specified once in the CustomServiceTask using @Property annotations on members of the CustomServiceTask, but the input for the process definition is provided by the user.

This is how it works at the moment. I'm trying to figure out what you want to do that is not supported by this structure, so please help me out Smiley Happy

For instance, you seem to suggest that you want to change the runtime class when modelling a diagram. Personally, I don't see a great number of use cases for this, since the idea of CustomServiceTasks is that the user is not concerned with runtime aspects, but needs a predefined building block that has standard runtime behavior the user doesn't ever see, but "just works". If you want to configure the delegate as a user, it would seem you're more of a developer and would be able to configure a normal service task anyway.

As for the properties, you already can use an expression as a user. In your delegate you must make sure that the members the value will be injected into is an Expression so you can resolve the value at runtime. So the user can choose to enter a static string in the property's field or use an expressionv(in the same field). I don't understand what functionality you are missing there. If the member of the runtime class is an expression, you can still resolve a static text the user has entered, so making all the fields an expression where you can reasonably expect the user to want to ever use one is the most flexible option.

jbrazil5
Champ in-the-making
Champ in-the-making
Okay I think I get it now. Thanks so much for taking the time to answer!

Just to make sure I understand :

1.) I create a CustomServiceTask, specify the JavaDelegate that will get called when it is executed by specifying it like so, @Runtime(javaDelegateClass = "my.awesome.activiti.delegate");

2.) Specify the CustomServiceTask input properties by annotating them like so, @Property(type = PropertyType.TEXT, displayName = "username", required = true)

3.) In my custom JavaDelegate, for each property I defined in the CustomServiceTask add an Expression variable, e.g. private Expression username;

4.) When using the CustomServiceTask in the designer if I want an expression to be injected for the "username" property I just have to type the expression into the property field(even though I specified PropertyType.TEXT) like normal e.g. ${username}. Because In the delegate I specified the field to be an Expression it will get injected properly.

jbrazil5
Champ in-the-making
Champ in-the-making
I just tried it and verified that it worked. Thanks so much for your time! Maybe I am just  a newbie and didn't understand very well how the expressions were injected to a JavaDelegate. I think it would help to have a note in the documentation that you can put an expression in the text fields. It kinda seemed like I could only put static strings in there. Either way, thanks a bunch!

http://www.youtube.com/watch?v=oIJKNwFC7Iw

tiesebarrell
Champ in-the-making
Champ in-the-making
Great to hear that got you going. And yes, the summary is correct.

Good idea to add a mention of this in the userguide. I'll make a note to include this.