workflow::case::new (public)

 workflow::case::new [ -no_notification ] -workflow_id workflow_id \
    [ -case_id case_id ] [ -object_id object_id ] [ -comment comment ] \
    [ -comment_mime_type comment_mime_type ] [ -user_id user_id ] \
    [ -assignment assignment ] [ -package_id package_id ] \
    [ -initial_action_id initial_action_id ]

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

Start a new case for this workflow and object.

Switches:
-no_notification (optional, boolean)
-workflow_id (required)
The ID of the workflow for the case.
-case_id (optional)
-object_id (optional)
The object_id which the case is about
-comment (optional)
-comment_mime_type (optional)
text/html, text/plain, text/pre, text/enhanced.
-user_id (optional)
-assignment (optional)
Array-list of role_short_name and list of party_ids to assign to roles before starting.
-package_id (optional)
-initial_action_id (optional)
Returns:
The case_id of the case.
Author:
Lars Pind <lars@collaboraid.biz>

Partial Call Graph (max 5 caller/called nodes):
%3 bug_tracker::bug::new bug_tracker::bug::new (public) workflow::case::new workflow::case::new bug_tracker::bug::new->workflow::case::new workflow::test::case_setup workflow::test::case_setup (public) workflow::test::case_setup->workflow::case::new ad_conn ad_conn (public) workflow::case::new->ad_conn db_transaction db_transaction (public) workflow::case::new->db_transaction workflow::action::fsm::edit workflow::action::fsm::edit (public) workflow::case::new->workflow::action::fsm::edit workflow::action::fsm::get workflow::action::fsm::get (public) workflow::case::new->workflow::action::fsm::get workflow::case::action::execute workflow::case::action::execute (public) workflow::case::new->workflow::case::action::execute

Testcases:
No testcase defined.
Source code:
    if { (![info exists user_id] || $user_id eq "") } {
        set user_id [ad_conn user_id]
    }

    if { (![info exists package_id] || $package_id eq "") } {
        set package_id [ad_conn package_id]
    }
    
    db_transaction {

        # Initial action
    if {0} {
        # get initial action not from cache
        array set row [workflow::get_not_cached -workflow_id $workflow_id]
        set initial_action_id $row(initial_action_id)
        array unset row
    }

    if {$initial_action_id eq ""} {
        set initial_action_id [workflow::get_element -workflow_id $workflow_id -element initial_action_id]
    }

        if { $initial_action_id eq "" } {
            # If there is no initial-action, we create one now
            # TODO: Should we do this here, or throw an error like we used to?
            # If we change this, we should throw an error instead

            set action_row(pretty_name) "Start"
            set action_row(pretty_past_tense) "Started"
            set action_row(trigger_type) "init"

            set states [workflow::fsm::get_states -workflow_id $workflow_id]
            
        if { [llength $states] == 0 } {
        error "workflow $workflow_id doesn't have any states"
        }

            # We use the first state as the initial state
            set action_row(new_state_id) [lindex $states 0]                   

            # Add the new initial action
            set initial_action_id [workflow::action::fsm::edit  -operation "insert"  -array action_row  -workflow_id $workflow_id]
        
        workflow::flush_cache -workflow_id $workflow_id
        
        } else {
            # NOTE: FSM-specific check here
            
            workflow::action::fsm::get -action_id $initial_action_id -array initial_action
            set new_state $initial_action(new_state)

            if { $new_state eq "" } {
                error "Initial action with short_name \"$initial_action(short_name)\" does not have any new_state. In order to be an initial state, it must have new_state set."
            }
        }

        # Insert the case
        set case_id [insert  -workflow_id $workflow_id  -case_id $case_id  -object_id $object_id]

        # Assign roles
        if { ([info exists assignment] && $assignment ne "") } {
            array set assignment_array $assignment
            workflow::case::role::assign -case_id $case_id -array assignment_array
        }


        # Execute the initial action
        workflow::case::action::execute  -no_notification=$no_notification_p  -case_id $case_id  -action_id $initial_action_id  -comment $comment  -comment_mime_type $comment_mime_type  -user_id $user_id  -package_id $package_id  -initial
    }
        
    return $case_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 ] | [ make this the default ]
Show another procedure: