workflow::case::action::notify (public)

 workflow::case::action::notify -case_id case_id -action_id action_id \
    -entry_id entry_id -comment comment \
    -comment_mime_type comment_mime_type

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

Send out notifications to relevant people.

Switches:
-case_id (required)
-action_id (required)
-entry_id (required)
-comment (required)
-comment_mime_type (required)

Partial Call Graph (max 5 caller/called nodes):
%3 workflow::case::action::execute workflow::case::action::execute (public) workflow::case::action::notify workflow::case::action::notify workflow::case::action::execute->workflow::case::action::notify _ _ (public) workflow::case::action::notify->_ acs_sc::invoke acs_sc::invoke (public) workflow::case::action::notify->acs_sc::invoke ad_decode ad_decode (public) workflow::case::action::notify->ad_decode ad_html_text_convert ad_html_text_convert (public) workflow::case::action::notify->ad_html_text_convert db_1row db_1row (public) workflow::case::action::notify->db_1row

Testcases:
No testcase defined.
Source code:
    # Get workflow_id
    workflow::case::get  -case_id $case_id  -array case

    workflow::get  -workflow_id $case(workflow_id)  -array workflow
    
    set hr [string repeat "=" 70]
    
    # TODO: Get activity log for top-case
    array set latest_action [lindex [workflow::case::get_activity_log_info_not_cached -case_id $case_id] end]

    # Variables used by I18N messages:
    set action_past_tense "$latest_action(action_pretty_past_tense)[ad_decode $latest_action(log_title) "" "" " $latest_action(log_title)"]"
    set user_name "$latest_action(user_first_names) $latest_action(user_last_name)"
    set user_email $latest_action(user_email)
    set latest_action_chunk [_ workflow.notification_email_latest_action_chunk]
    
    if { $latest_action(comment) ne "" } {
        append latest_action_chunk ":\n\n    [join [split [ad_html_text_convert -from $latest_action(comment_mime_type) -to "text/plain" -maxlen 66 -- $latest_action(comment)] "\n"] "\n    "]"
    }
    
    # Callback to get notification info 
    # TODO: Should this be the parent/top-workflow that does this?
    set contract_name [workflow::service_contract::notification_info]
    set impl_names [workflow::get_callbacks  -workflow_id $case(workflow_id)  -contract_name $contract_name]
    # We only use the first callback
    set impl_name [lindex $impl_names 0]
    
    if { $impl_name ne "" } {
        set notification_info [acs_sc::invoke  -contract $contract_name  -operation "GetNotificationInfo"  -impl $impl_name  -call_args [list $case_id $case(object_id)]]
        
    }

    # Make sure the notification info list has at least 4 elements, so we can do below lindex's safely
    lappend notification_info {} {} {} {}
    
    set object_url [lindex $notification_info 0]
    set object_one_line [lindex $notification_info 1]
    set object_details_list [lindex $notification_info 2]
    set object_notification_tag [lindex $notification_info 3]

    if { $object_one_line eq "" } {
        # Default: Case #$case_id: acs_object__name(case.object_id)

        set object_id $case(object_id)
        db_1row select_object_name {} -column_array case_object

        set object_one_line "[_ workflow.Case] #$case_id: $case_object(name)"
    }

    # Roles and their current assignees
    foreach role_id [workflow::get_roles -workflow_id $case(workflow_id)] {
        set label [lang::util::localize [workflow::role::get_element -role_id $role_id -element pretty_name]]
        foreach assignee_arraylist [workflow::case::role::get_assignees -case_id $case_id -role_id $role_id] {
            array set assignee $assignee_arraylist
            lappend object_details_list $label "$assignee(name) ($assignee(email))"
            set label {}
        }
    }

    # Find the length of the longest label
    set max_label_len 0
    foreach { label value } $object_details_list {
        if { [string length $label] > $max_label_len } {
            set max_label_len [string length $label]
        }
    }
                     
    # Output notification info
    set object_details_lines [list]
    foreach { label value } $object_details_list {
        if { $label ne "" } {
            lappend object_details_lines "$label[string repeat " " [expr {$max_label_len - [string length $label]}]] : $value"
        } else {
            lappend object_details_lines "[string repeat " $max_label_len]   $value"
        }
    }
    set object_details_chunk [join $object_details_lines "\n"]

    set activity_log_chunk [workflow::case::get_activity_text -case_id $case_id]

    set the_subject "[ad_decode $object_notification_tag "" "" "\[$object_notification_tag\] "]$object_one_line: $latest_action(action_pretty_past_tense) [ad_decode $latest_action(log_title) "" "" "$latest_action(log_title) "]by $latest_action(user_first_names) $latest_action(user_last_name)"

    # List of user_id's for people who are in the assigned_role to any enabled actions
    # This takes deputies into account

#XXXXX Verify this ... probably wrong
    set assigned_role_id [workflow::action::get_assigned_role -action_id $action_id]
    set assignee_list [list]
    foreach assignee_array [workflow::case::role::get_assignees  -case_id $case_id  -role_id $assigned_role_id] {
        array set ass $assignee_array
        lappend assignee_list $ass(party_id)
    }
        
    # List of users who play some role in this case
    # This takes deputies into account
    set case_player_list [db_list case_players {}]

    # Get pretty_name and pretty_plural for the case's object type
    set object_id $case(object_id)
    db_1row select_object_type_info {} -column_array object_type

    # Get name of the workflow's object
    set object_id $workflow(object_id)
    db_1row select_object_name {} -column_array workflow_object

    set next_action_chunk(workflow_assignee) [_ workflow.lt_You_are_assigned_to_t]

    set next_action_chunk(workflow_my_cases) [_ workflow.lt_You_are_a_participant]

    set next_action_chunk(workflow_case) [_ workflow.lt_You_have_a_watch_on_t]

    set next_action_chunk(workflow) [_ workflow.lt_You_have_requested_to]

    # Initialize stuff that depends on the notification type
    foreach type { 
        workflow_assignee workflow_my_cases workflow_case workflow
    } {
        set subject($type$the_subject
        set body($type"$hr
$object_one_line
$hr

$latest_action_chunk

$hr

$next_action_chunk($type)[ad_decode $object_url "" "" "\n\n[_ workflow.lt_Please_click_here_to_]\n\n$object_url"]

$hr[ad_decode $object_details_chunk "" "" "\n$object_details_chunk\n$hr"]

$activity_log_chunk

$hr
"
        set force_p($type) 0
        set subset($type) {}
    }

    set force_p(workflow_assignee) 1
    set subset(workflow_assignee) $assignee_list
    set subset(workflow_my_cases) $case_player_list
    
    set notified_list [list]

    foreach type { 
        workflow_assignee workflow_my_cases workflow_case workflow
    } {
            set object_id [workflow::case::get_notification_object  -type $type  -workflow_id $case(workflow_id)  -case_id $case_id]

        if { $object_id ne "" && ($type eq "workflow" || $subset($type) ne "" || $type eq "workflow_case")} {
                set notified_list [concat $notified_list [notification::new  -type_id [notification::type::get_type_id -short_name $type]  -object_id $object_id  -action_id $entry_id  -response_id $case(object_id)  -notif_subject $subject($type)  -notif_text $body($type)  -already_notified $notified_list  -subset $subset($type)  -return_notified]]
            }
        }
Generic XQL file:
<fullquery name="workflow::case::action::notify.select_object_name">
    <querytext>
        select acs_object.name(:object_id) as name from dual
    </querytext>
</fullquery>

<fullquery name="workflow::case::action::notify.enabled_action_assignees">
    <querytext>
        select distinct rum.user_id
        from   workflow_cases c,
               workflow_actions a,
               workflow_case_role_user_map rum 
        where  c.case_id = :case_id
        and    a.workflow_id = c.workflow_id
        and    (a.always_enabled_p = 't' or 
                exists (select 1 
                        from   workflow_fsm_action_en_in_st waeis,
                               workflow_case_fsm c_fsm
                        where  waeis.action_id = a.action_id
                        and    c_fsm.case_id = c.case_id
                        and    waeis.state_id = c_fsm.current_state)
               )
        and    rum.case_id = c.case_id
        and    rum.role_id = a.assigned_role
    </querytext>
</fullquery>

<fullquery name="workflow::case::action::notify.case_players">
    <querytext>
        select distinct user_id
        from   workflow_case_role_user_map
        where  case_id = :case_id
    </querytext>
</fullquery>

<fullquery name="workflow::case::action::notify.select_object_type_info">
    <querytext>
        select lower(pretty_name) as pretty_name,
               lower(pretty_plural) as pretty_plural
        from   acs_object_types ot,
               acs_objects o
        where  o.object_id = :object_id
        and    ot.object_type = o.object_type
    </querytext>
</fullquery>
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: