3

When I start my workflow, I want the option to assign it to somebody. If nobody is chosen, I want to default to assign it to the initiator.

Is this possible to do without creating a new model that extends bpm:assignee? If not, how would that extension be accomplished?

I believe this answer from Jeff Potts is relevant: https://stackoverflow.com/a/9418066/4542428

Note: I am using Community edition 4.2

EDIT: Stefan's answer got me the vast majority of the way to the answer, but it seems that I am somehow referencing the value of the association incorrectly. Context: I've never used associations, and this is likely just my failure to understand their difference from types and aspects.

From my model:

<type name="deliveryTicketWorkflow:start">
      <parent>bpm:startTask</parent>
      <properties>      
      </properties>
      <associations />
      <overrides />
      <mandatory-aspects>
        <aspect>deliveryTicketWorkflow:pmAspect</aspect>
        <aspect>deliveryTicketWorkflow:requestDetailsAspect</aspect>
      </mandatory-aspects>
</type>
<aspect name="deliveryTicketWorkflow:pmAspect">
        <associations>
            <association name="deliveryTicketWorkflow:assignedPM">
                    <source>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </source>
                    <target>
                        <class>cm:person</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
        </associations>
    </aspect>

Which is used by my config as:

<config condition="activiti$deliveryTicketWorkflow" evaluator="string-compare">
        <forms>
            <form>
                <field-visibility>
...
                    <show id="deliveryTicketWorkflow:assignedPM" />
...
                </field-visibility>
                <appearance>
...
                    <field id="deliveryTicketWorkflow:assignedPM" label-id="Project Manager" />
...
               </appearance>
            </form>
        </forms>
    </config>

My config for deliveryTicketworkflow:start is identical. This successfully displays the person selector, without making it mandatory, exactly 100% as Stefan said it would.

In my bpmn workflow definition, I then have these snippets in an execution listener for the start event:

          if(!execution.getVariable("deliveryTicketWorkflow_assignedPM")){
            execution.setVariable("deliveryTicketWorkflow_assignedPM", initiator);
          }
...
         deliveryTicket.properties["dtdlm:projectManager"] = execution.getVariable("deliveryTicketWorkflow_assignedPM").properties.firstName + " " + execution.getVariable("deliveryTicketWorkflow_assignedPM").properties.lastName;

When the workflow is run and I select somebody as the PM, that final line (where the first and last name of the PM is grabbed) returns a value of undefined for "deliveryTicketWorkflow_assignedPM". When it is left blank, everything works swimmingly but the General Info section of the Workflow description still lists the Project Manager as (None).

Community
  • 1
  • 1
CJK
  • 118
  • 8

1 Answers1

4

You could indeed customize the people picker, as jeff describes, but it requires quite some coding effort.

Alternatively you could use a workflow executionlistener for event start, and use it to set the bpm_assignee variable to the initiator in case it was empty on the form:

Add listener to you bpmn20:

 <activiti:executionListener event="start" class="com.mycomp.Executionlistener"></activiti:executionListener>

In your first usertask, define the assignee to the association property in your workflow start form.

 <userTask id="firsttask" name="firsttask" activiti:assignee="${mymodel.myassoc.properties.userName}" >

Also add this association to your start task content model.

Code in com.mycomp.Executionlistener will look like this:

public void notify(DelegateExecution execution) throws Exception {
   if (execution.getVariable("mymodel_myassoc") == null ){

        ActivitiScriptNode userScriptNode= (ActivitiScriptNode) execution.getVariable("initiator");
        execution.setVariable("mymodel_myassoc",userScriptNode);
   }
 }
Stefan De Laet
  • 1,409
  • 11
  • 20
  • That's the general approach I was leaning toward, but I was under the impression that you couldn't get the workflow to the point of firing the execution listener without having all mandatory fields (i.e. bpm:assignee) filled. – CJK Feb 23 '16 at 14:01
  • try using a custom field for you assignee in the start form, and make it non mandatory. Then use this field in your bmp first task as the assignee. I ve updated the answer – Stefan De Laet Feb 23 '16 at 14:48
  • I thought that this had resolved my issue, because it worked when I left the selector blank, but I'm doing something terribly wrong and never actually referencing the value of the selector. Updating original question and re-opening. – CJK Feb 26 '16 at 14:00
  • Re-accepting this answer. You were 100% spot on. I just for got to add 'set="info"' in the field line of the config – CJK Feb 26 '16 at 15:03