Workflows

View as Markdown

A workflow is a state machine that an object moves through, such as Draft, Waiting for Approval, Approved. In M-Files the workflow and the state are property values of the object version, so moving an object to another state is a property change that the server checks against the workflow's rules.

The pieces

Item Value list Object property
Workflow 7 (Workflows) 38 Workflow, a lookup to value list 7
State 8 (Workflow States), owned by value list 7 39 Workflow State, a lookup to value list 8
State transition 17 (State transitions) 99 State transition, a lookup to value list 17
Time of the last state change 40 Moved into current state, set by the server

Each state belongs to one workflow. State IDs and transition IDs are their own ID spaces: state 135 and transition 2 below are unrelated numbers.

Sample Vault workflow 106 "Reviewing drawings"

  (no state) --[1]--> 135 Listed for approval --[2]--> 136 Approved
                                  ^                          |
                                  '----------[3]-------------'

Classes link to workflows: ObjectClass.default_workflow proposes one, and with force_workflow true every object of the class must use it. In the Sample Vault, class 2 (Purchase Invoice) forces workflow 102; creating an invoice without it fails with 'The specified workflow "(empty)" is not allowed for this class.' A workflow's object_class_id in Workflow is -3 when it is meant for all classes.

Reading workflows and the allowed transitions

Changing the state

Set property 39 to the new state, in any call that writes properties: SetProperties, CheckIn or AddObject.

SetPropertiesRequest
  obj_ver { obj_id { type: 0 item_id { internal_id: 546 } }
            version { type: OBJ_VER_VERSION_TYPE_SPECIFIC internal_version: 1 } }
  allow_modifying_checked_in_object: true
  properties { property_def: 39
               value { type: DATATYPE_LOOKUP data { lookup { value_list_item_info {
                       obj_id { type: 8 item_id { internal_id: 136 } } } } } } }

Run against the Sample Vault, this moved a document from state 135 to 136 and created version 2 with property 40 set to the time of the change. Alternatively, set property 99 to a transition ID: the server then sets property 39 to the transition's target state.

The server checks the change and answers with an error when it is not allowed (messages shortened; the server puts line breaks between their parts):

Situation Error message
No transition leads from the current state to the new one, or the caller may not use it 'Access denied. The state transition "(no state) -> Approved" is not allowed.'
The new state's preconditions are not met "The preconditions specified for the new state are not satisfied. ..." followed by the failing condition
The class forces a different workflow 'The specified workflow "(empty)" is not allowed for this class.'

To start an object in a workflow, set property 38 and the first state in property 39 together. Setting only property 38 leaves the state empty.

A state can carry actions that run when an object enters it. In the Sample Vault, the first state of the invoice workflow is defined to replace the object's permissions and to assign the object to a user, so a state change can change who can see the object.

Electronic signatures

A state transition can require an electronic signature, for example for regulated approvals. GetStateTransitionSignatureSettings returns the transition's ElectronicSignatureSettings (is_required, the reason and meaning to show, where the signature is stored). Requests that change properties have a signature field for the signature; the remarks of SetProperties describe what it holds. The workflows of the Sample Vault require no signatures.

The workflow state guide puts these calls together.