Important

You are browsing the documentation for version 3.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Workflow Configuration Example

The workflow configuration that we are going to illustrate has two entities:

  • Phone Call

  • Phone Conversation

Workflow Diagram

When Workflow Item is created, it is connected to the Phone Call. On the first “Start Call” step , a user can proceed to the “Call Phone Conversation Step” if the recipient answered, or to the “End Phone Call” step if the recipient did not.

On step “Call Phone Conversation”, the user enters Workflow Data and navigates to the “End Phone Call” step via the “End conversation” transition. On this transition, a new Entity of Phone Conversation is created and assigned to the Phone Call entity.

Configuration

  1 workflows:
  2     phone_call:
  3         entity: Acme\Bundle\DemoWorkflowBundle\Entity\PhoneCall
  4         start_step: start_call
  5         steps:
  6             start_call:
  7                 allowed_transitions:
  8                     - connected
  9                     - not_answered
 10             start_conversation:
 11                 allowed_transitions:
 12                     - end_conversation
 13             end_call:
 14                 is_final: true
 15         attributes:
 16             phone_call:
 17                 type: entity
 18                 options:
 19                     class: Acme\Bundle\DemoWorkflowBundle\Entity\PhoneCall
 20             call_timeout:
 21                 type: integer
 22             call_successfull:
 23                 type: boolean
 24             conversation_successful:
 25                 type: boolean
 26             conversation_comment:
 27                 type: string
 28             conversation_result:
 29                 type: string
 30             conversation:
 31                 type: entity
 32                 options:
 33                     class: Acme\Bundle\DemoWorkflowBundle\Entity\PhoneConversation
 34         variable_definitions:
 35             variables:
 36                 var1:
 37                     type: 'string'
 38                     value: 'Var1Value'
 39         transitions:
 40             start_call:
 41                 is_start: true                         # this transition used to start new workflow
 42                 step_to: start_conversation            # next step after transition performing
 43                 transition_definition: create_call     # link to definition of conditions and post actions
 44                 init_context_attribute: init_source    # name of variable which contains init context
 45                 init_entities:                         # list of view page entities where will be displayed transition button
 46                     - 'Oro\Bundle\UserBundle\Entity\User'
 47                     - 'Oro\Bundle\TaskBundle\Entity\Task'
 48                 init_datagrids:                        # list of datagrids on which rows start transition buttons should be shown for start transition from not related entity
 49                     - user_entity_grid
 50                     - task_entity_grid
 51             connected:
 52                 step_to: start_conversation
 53                 transition_definition: connected_definition
 54             not_answered:
 55                 step_to: end_call
 56                 transition_definition: not_answered_definition
 57             end_conversation:
 58                 step_to: end_call
 59                 form_options:
 60                     attribute_fields:
 61                         conversation_comment:
 62                             options:
 63                 transition_definition: end_conversation_definition
 64         transition_definitions:
 65             create_call:
 66                 conditions:    # Check that the transition start from the entity page
 67                     '@and':
 68                         - '@not_empty': [$init_source.entityClass]
 69                         - '@not_empty': [$init_source.entityId]
 70                 actions:
 71                     - '@find_entity':
 72                         class: $init_source.entityClass
 73                         identifier: $init_source.entityId
 74                         attribute: $.user
 75                     - '@tree':
 76                         conditions:
 77                             - '@instanceof': [$init_source.entityClass, 'Oro\Bundle\UserBundle\Entity\User']
 78                         actions:
 79                             - '@assign_value': [$entity.phone, $.user.phone]
 80                             - '@flush_entity': $entity    # flush created entity
 81             connected_definition: # Try to make call connected
 82                 # Check that timeout is set
 83                 conditions:
 84                     @not_blank: [$call_timeout]
 85                 # Set call_successfull = true
 86                 actions:
 87                     - @assign_value:
 88                         parameters: [$call_successfull, true]
 89             not_answered_definition: # Callee did not answer
 90                 # Make sure that caller waited at least 60 seconds
 91                 conditions: # call_timeout not empty and >= 60
 92                     @and:
 93                         - @not_blank: [$call_timeout]
 94                         - @ge: [$call_timeout, 60]
 95                 # Set call_successfull = false
 96                 actions:
 97                     - @assign_value:
 98                         parameters: [$call_successfull, false]
 99             end_conversation_definition:
100                 conditions:
101                     # Check required properties are set
102                     @and:
103                         - @not_blank: [$conversation_result]
104                         - @not_blank: [$conversation_comment]
105                         - @not_blank: [$conversation_successful]
106                 # Create PhoneConversation and set it's properties
107                 # Pass data from workflow to conversation
108                 actions:
109                     - @create_entity: # create PhoneConversation
110                         parameters:
111                             class: Acme\Bundle\DemoWorkflowBundle\Entity\PhoneConversation
112                             attribute: $conversation
113                             data:
114                                 result: $conversation_result
115                                 comment: $conversation_comment
116                                 successful: $conversation_successful
117                                 call: $phone_call

Translation File Configuration

To define translatable textual representation of the configuration fields, create translation file DemoWorkflowBundle\Resources\translations\workflows.en.yml with the following content.

 1 oro:
 2     workflow:
 3         phone_call:
 4             label: 'Demo Call Workflow'
 5             step:
 6                 start_call:
 7                     label: 'Start Phone Call'
 8                 start_conversation:
 9                     label: 'Call Phone Conversation'
10                 end_call:
11                     label: 'End Phone Call'
12             attribute:
13                 phone_call:
14                     label: 'Phone Call'
15                 call_timeout:
16                     label: 'Call Timeout'
17                 call_successfull:
18                     label: 'Call Successful'
19                 conversation_successful:
20                     label: 'Conversation Successful'
21                 conversation_comment:
22                     label: 'Conversation Comment'
23                 conversation_result:
24                     label: 'Conversation Result'
25                 conversation:
26                     label: Conversation
27             transition:
28                 connected:
29                     label: Connected
30                     warning_message: 'Going to connect...'
31                 not_answered:
32                     label: 'Not answered'
33                 end_conversation:
34                     label: 'End conversation'
35                     attribute:
36                         conversation_comment:
37                             label: 'Comment for the call result'

As usual, for Symfony translations (messages) files, the structure of nodes can be grouped by key dots. This code above provides the full tree just as an example. See more about translations in the Translations Wizard topic.

PhoneCall Entity

 1 <?php
 2
 3 namespace Acme\Bundle\DemoWorkflowBundle\Entity;
 4
 5 use Doctrine\Common\Collections\ArrayCollection;
 6 use Doctrine\ORM\Mapping as ORM;
 7
 8 /**
 9  * @ORM\Table(name="acme_demo_workflow_phone_call")
10  * @ORM\Entity
11  */
12 class PhoneCall
13 {
14     /**
15      * @ORM\Column(name="id", type="integer")
16      * @ORM\Id
17      * @ORM\GeneratedValue(strategy="AUTO")
18      */
19     private $id;
20
21     /**
22      * @ORM\Column(name="number", type="string", length=255)
23      */
24     private $number;
25
26     /**
27      * @ORM\Column(name="name", type="string", length=255, nullable=true)
28      */
29     private $name;
30
31     /**
32      * @ORM\Column(name="description", type="text", nullable=true)
33      */
34     private $description;
35
36     /**
37      * @ORM\OneToMany(targetEntity="PhoneConversation", mappedBy="call")
38      **/
39     private $conversations;
40
41     public function __construct()
42     {
43         $this->conversations = new ArrayCollection();
44     }
45
46     public function getId()
47     {
48         return $this->id;
49     }
50
51     public function setNumber($number)
52     {
53         $this->number = $number;
54         return $this;
55     }
56
57     public function getNumber()
58     {
59         return $this->number;
60     }
61
62     public function setName($name)
63     {
64         $this->name = $name;
65         return $this;
66     }
67
68     public function getName()
69     {
70         return $this->name;
71     }
72
73     public function setDescription($description)
74     {
75         $this->description = $description;
76
77         return $this;
78     }
79
80     public function getDescription()
81     {
82         return $this->description;
83     }
84
85     public function getConversations()
86     {
87         return $this->conversations;
88     }
89 }

PhoneConversation Entity

 1 <?php
 2
 3 namespace Acme\Bundle\DemoWorkflowBundle\Entity;
 4
 5 use Doctrine\ORM\Mapping as ORM;
 6
 7 /**
 8  * @ORM\Table(name="acme_demo_workflow_phone_conversation")
 9  * @ORM\Entity
10  */
11 class PhoneConversation
12 {
13     /**
14      * @ORM\Column(name="id", type="integer")
15      * @ORM\Id
16      * @ORM\GeneratedValue(strategy="AUTO")
17      */
18     private $id;
19
20     /**
21      * @ORM\ManyToOne(targetEntity="PhoneCall", inversedBy="conversations")
22      * @ORM\JoinColumn(name="call_id", referencedColumnName="id")
23      */
24     private $call;
25
26     /**
27      * @ORM\Column(name="result", type="string", length=255, nullable=true)
28      */
29     private $result;
30
31     /**
32      * @ORM\Column(name="comment", type="string", length=255, nullable=true)
33      */
34     private $comment;
35
36     /**
37      * @ORM\Column(name="successful", type="boolean", nullable=true)
38      */
39     private $successful;
40
41     public function getId()
42     {
43         return $this->id;
44     }
45
46     public function setResult($result)
47     {
48         $this->result = $result;
49
50         return $this;
51     }
52
53     public function getResult()
54     {
55         return $this->result;
56     }
57
58     public function setComment($comment)
59     {
60         $this->comment = $comment;
61         return $this;
62     }
63
64     public function getComment()
65     {
66         return $this->comment;
67     }
68
69     public function setSuccessful($successful)
70     {
71         $this->successful = $successful;
72         return $this;
73     }
74
75     public function isSuccessful()
76     {
77         return $this->successful;
78     }
79
80     public function setCall($call)
81     {
82         $this->call = $call;
83         return $this;
84     }
85
86     public function getCall()
87     {
88         return $this->call;
89     }
90 }

Flow Diagram

Workflow Diagram