Callbacks

"Callbacks" allow further customization of the product by executing custom code at certain events without breaking the products upgradeability.  

The following callbacks are available for each of the actions performed on an Object:

Creation of a new Object: After

View of an Object: View

Update of an Object: Before & After

Deletion of an Object: Before

Implementation

Callbacks are called from the "Audit" functions. 

Example

A custom callback sends out email notifications based on custom business rules:
(Please note that in ]po[ "tickets" are implemented as "projects")

Call to im_project_audit in page that is creating the ticket:

# /packages/intranet-helpdesk/www/new.tcl
....

if {[exists_and_not_null ticket_id]} {
    # Check if the ticket exists
    set ticket_exists_p [db_string ticket_exists_p "select count(*) from im_tickets where ticket_id = :ticket_id"]

    # Write Audit Trail
    im_project_audit -project_id $ticket_id -action before_update
}

...

Callback implementation in "im_project_audit"
# /packages/intranet-core/tcl/intranet-audit-procs.tcl
...
    if {$catch_error_p} {
        if {[catch {
            callback ${object_type}_${action} -object_id $object_id -status_id $status_id -type_id $type_id
        } err_msg]} {
            ns_log Error "im_project_audit: Error with callback ${object_type}_${action} -object_id $object_id -status_id $status_id -type_id $type_id:\n$err_msg"
        }
    } else {
        callback ${object_type}_${action} -object_id $object_id -status_id $status_id -type_id $type_id
    }
...

Actual implementation of the callback:

# /packages/intranet-core/tcl/intranet-audit-procs.tcl

ad_proc -public -callback im_ticket_after_create -impl intranet-cust-projop-procs {
    {-object_id:required}
    {-status_id ""}
    {-type_id ""}
} {
    - Notify PM's of SLA about ticket creation
    - Auto assign users
} {

    # -----------------------------------------------
    # Send Notifications to Ticket Members
    # -----------------------------------------------

    set current_user_id [ad_get_user_id]
    set sql "select ticket_description, ticket_quote_comment from im_tickets where ticket_description <> '' or ticket_quote_comment <> ''"
    db_1row get_ticket_comments "select ticket_description, ticket_quote_comment from im_tickets where ticket_id = :object_id"
    set sla_id [db_string get_sla_id "select parent_id from im_projects where project_id = :object_id" -default 0]

        # get PM's from SLA
        set sql "
                select
                        r.object_id_two
                from
                        acs_rels r,
                        im_biz_object_members m
                where
                        r.object_id_one = :sla_id
                        and r.rel_id = m.rel_id
                        and m.object_role_id in (1301,1302,1303)
        "

    set project_name [db_string get_data "select project_name from im_projects where project_id = :object_id" -default ""]
    set subject "[lang::message::lookup "" intranet-helpdesk.Mail_Subject_New_Ticket "New ticket"]: $project_name"
    set base_url  [parameter::get -package_id [apm_package_id_from_key acs-kernel] -parameter "SystemURL" -default 60]
    set body "$base_url/intranet-helpdesk/new?form_mode=display&ticket_id=$object_id"
    append body "\n $ticket_description \n $ticket_quote_comment"

    db_foreach col $sql {
        set sql_inner "select acs_mail_nt__post_request (:current_user_id, :object_id_two, 'f', :subject, :body, 0)"
        if {[catch {
            set foo [db_string send_notif_email $sql_inner -default 0]
        } err_msg]} {
            ns_log NOTICE "intranet-cust-projop-procs::callback - ERROR Notification mail not delivered - $err_msg"
        }
    }
	
	# ------------------------------------------------------
	# Auto-Assignment of internal Employees to a Ticket
	# ------------------------------------------------------

    if { 866711 == $sla_id } {
        # Add FD
        im_biz_object_add_role 250819 $object_id 1300

        # Add DV
        im_biz_object_add_role 191809 $object_id 1300
    }
}

  Contact Us
  Project Open Business Solutions S.L.

Calle Aprestadora 19, 12o-2a

E-08907 Hospitalet de Llobregat (Barcelona)

 Tel Europe: +34 932 202 088
 Tel US: +1 415 429 5995
 Mail: info@project-open.com