workflow::case::action::fsm::execute_state_change (private)

 workflow::case::action::fsm::execute_state_change [ -initial ] \
    [ -case_id case_id ] [ -action_id action_id ] \
    [ -enabled_action_id enabled_action_id ] \
    [ -parent_enabled_action_id parent_enabled_action_id ]

Defined in packages/workflow/tcl/case-procs.tcl

Modify the state of the case as required when executing the given action.

Switches:
-initial
(boolean) (optional)
Set this if this is an initial action.
-case_id
(optional)
The ID of the case.
-action_id
(optional)
The ID of the action
-enabled_action_id
(optional)
The ID of the action
-parent_enabled_action_id
(optional)
Specify this, if this is an initial action.
Author:
Lars Pind <lars@collaboraid.biz>

Partial Call Graph (max 5 caller/called nodes):
%3 workflow::case::action::execute workflow::case::action::execute (public) workflow::case::action::fsm::execute_state_change workflow::case::action::fsm::execute_state_change workflow::case::action::execute->workflow::case::action::fsm::execute_state_change db_dml db_dml (public) workflow::case::action::fsm::execute_state_change->db_dml db_transaction db_transaction (public) workflow::case::action::fsm::execute_state_change->db_transaction workflow::action::get workflow::action::get (public) workflow::case::action::fsm::execute_state_change->workflow::action::get workflow::case::action::get_enabled_action_id workflow::case::action::get_enabled_action_id (private) workflow::case::action::fsm::execute_state_change->workflow::case::action::get_enabled_action_id workflow::case::enabled_action_get workflow::case::enabled_action_get (public) workflow::case::action::fsm::execute_state_change->workflow::case::enabled_action_get

Testcases:
No testcase defined.
Source code:

    db_transaction {

        if { $case_id eq "" || $action_id eq "" } {
            if { $enabled_action_id eq "" } {
                error "You must supply either case_id and action_id, or enabled_action_id"
            }
        } 

        if { $enabled_action_id eq "" } {
            if { $initial_p } {
                set enabled_action_p {}
                # We rely on parent_enabled_action_id being set by the caller here
            } else {
                # This will not work with dynamic actions, but is necessary for initial actions
                set enabled_action_id [workflow::case::action::get_enabled_action_id  -case_id $case_id  -action_id $action_id  -parent_enabled_action_id $parent_enabled_action_id]
            }
        }

        if { $enabled_action_id ne "" } {
            workflow::case::enabled_action_get -enabled_action_id $enabled_action_id -array enabled_action
            # Even if these are provided, we override them with the DB call
            set case_id $enabled_action(case_id)
            set action_id $enabled_action(action_id)
            set parent_enabled_action_id $enabled_action(parent_enabled_action_id)
        }

        # Find the new state from the action
        workflow::action::get -action_id $action_id -array action
        set new_state_id $action(new_state_id)

        # Actually change the state, if any state change
        if { $new_state_id ne "" } {
            # Delete any existing state with this parent_enabled_action_id

            if { $parent_enabled_action_id eq "" } {
                db_dml delete_fsm_state {
                    delete 
                    from   workflow_case_fsm
                    where  case_id = :case_id
                    and    parent_enabled_action_id is null
                }
            } else {
                db_dml delete_fsm_state {
                    delete 
                    from   workflow_case_fsm
                    where  case_id = :case_id
                    and    parent_enabled_action_id = :parent_enabled_action_id
                }
            }

            # Insert the new one
            db_dml insert_fsm_state {
                insert into workflow_case_fsm (case_id, parent_enabled_action_id, current_state)
                values (:case_id, :parent_enabled_action_id, :new_state_id)
            }
        }
    }
Generic XQL file:
packages/workflow/tcl/case-procs.xql

PostgreSQL XQL file:
packages/workflow/tcl/case-procs-postgresql.xql

Oracle XQL file:
packages/workflow/tcl/case-procs-oracle.xql

[ hide source ]
Show another procedure: