SDU
Personal tools

SPELL CODE to to add event at 50% and 75% of the time between schedule start time and duration

From SDU

Jump to: navigation, search
SPELL - Cancel and Add events based on the scheduling time in CO in ServiceDesk Manager R12.5

This code add 2 events to CO one that fires at 50% of the scheduled time and another at 75%.

The 50% starts at sched_start_time and fires at sched_start_time + duration /2 The 75% starts at sched_start_time and fires at sched_start_time + duration /4*3

Whenever there is a change this code check if there are similar events and cancel them.

STEP1

Trigger to add, create a z_my_event_sched_end_date.mod and put at $NX_ROOT/site/mods/majic with the following code, and restart the service desk:

OBJECT chg {
        TRIGGERS {
        POST_VALIDATE z_my_event_sched_end_date( persistent_id, sched_start_date, sched_end_date, sched_duration) 250 FILTER( EVENT("INSERT UPDATE") && active != 0 && sched_start_date != NULL && sched_duration >0);
        };
    };

STEP2

SPELL code create a z_my_event_sched_end_date.spl and put at $NX_ROOT/site/mods/majic with the following code and kill the process spel_srv or restart the servicedesk:

////////////////////////////////////////////////////////////////////////////////
// Module:              z_my_event_sched_end_date.spl
// Created:             10-02-2011
// Author:              ribru02@ca.com
////////////////////////////////////////////////////////////////////////////////
// Description:
//
//    Spel to add event when sched_duration or sched_start_date are inserted or updated
//    Add and remove fixed events. Add 2 events one to advise at 50% of the elapsed time and other for 75% of the elapsed time
//        Starting the event at sched_start_time delaying it duration/2 (50% between start and end sechduled time)
//    Starting the event at sched_start_time  and  delaying it duration/4*3 (75% between start and end sechduled time)
//
//Fired with the following trigger:
//OBJECT chg {
//  TRIGGERS {
//    POST_VALIDATE z_my_event_sched_end_date( persistent_id, sched_start_date, sched_end_date, sched_duration) 250 FILTER( EVENT("INSERT UPDATE") && active != 0 && sched_start_date != NULL && sched_duration >0);
//  };
//};
//
////////////////////////////////////////////////////////////////////////////////
//History
//v1.0 - ribru02@ca.com - First version
////////////////////////////////////////////////////////////////////////////////
#define  VERSION "v1.0"
 
 
 
// DEBUG 0 for no debug
// DEBUG 1 for debug
 
 
 
#define DEBUG 2
 
 
 
 
chg::z_my_event_sched_end_date (...)
{
 
////////////////////////////////////////////////////////////////////////////////
//vars
////////////////////////////////////////////////////////////////////////////////
        date schedule_start_date_old,schedule_start_date_new, schedule_start_date_75;
        duration duration_schedule_old,duration_schedule_new, duration_50, duration_75;
        string event_name_50, event_name_75, event_name_50_tmpl_persid,event_name_75_tmpl_persid;
        object atev_dob, atev_list, group_leader;
        string persistent_id,method;
        string wc;
        int atev_count, i;
 
        method  = "z_my_event_sched_end_date"+"_"+ VERSION;
 
        persistent_id=argv[3];
        schedule_start_date_old = argv[5];
        schedule_start_date_new = argv[6];
        duration_schedule_old = argv[11];
        duration_schedule_new = argv[12];
        //UPDATE YOUR EVENTS HERE
        event_name_50= "Increase Priority base on scheduled time 50%";
        event_name_50_tmpl_persid="evt:7649776";
        event_name_75= "Increase Priority base on scheduled time 75%";
        event_name_75_tmpl_persid="evt:7649777";
 
 
////////////////////////////////////////////////////////////////////////////////
//Previous validation
//If there is no change in one of the field there is no calculation
///////////////////////////////////////////////////////////////////////////////
 
if (DEBUG) logf(SIGNIFICANT,"=========== START : %s %s:%s ===========",method,type,chg_ref_num);
if (DEBUG == 2) logf(SIGNIFICANT,"%s - CO nº %s - NºArgs: %s => %s = %s -> %s| %s = %s -> %s | %s = %s -> %s ", method, chg_ref_nuu
m, argv[0],argv[4], argv[5], argv[6], argv[7],argv[8], argv[9], argv[10], argv[11],argv[12]);
 
 
if (!((schedule_start_date_old == schedule_start_date_new) && (duration_schedule_old == duration_schedule_new)))
{
        //getting group leader
                send_wait(0, top_object(), "get_co_group");
                group_leader = msg[0];
        ////////////////////////////////////////////////////////////////////////////////
        //calculation metrics
        //fire 50% and new event fire 75% of time duration
        ////////////////////////////////////////////////////////////////////////////////
                duration_50=(duration)((int)duration_schedule_new/2);
                duration_75=(duration)((int)duration_schedule_new/4*3);
 
        ////////////////////////////////////////////////////////////////////////////////
        //debug Info
        ////////////////////////////////////////////////////////////////////////////////
 
 
        ////////////////////////////////////////////////////////////////////////////////
        //remove existing events before adding new ones
        ////////////////////////////////////////////////////////////////////////////////
 
            // Identify the persids of the events to be deleted.
                wc = format("(event_tmpl = '%s' OR event_tmpl = '%s') AND obj_id = '%s' AND status_flag = 2", event_name_50_tmpl_persid,event_name_75_tmpl_persid,persistent_id);
                send_wait(0, top_object(), "call_attr", "atev", "sync_fetch", "STATIC", wc, -1, 0);
                atev_list = msg[0];
                atev_count = msg[1];
                if (DEBUG) logf(SIGNIFICANT, "%s - need to cancel %s event for CO %s", method, atev_count,chg_ref_num);
                if (atev_count > 0) {
                        for (i=0;i<atev_count;i++) {
                                send_wait(0, atev_list, "dob_by_index", "DEFAULT", i, i);
                                atev_dob = msg[0];
                                send_wait(0, group_leader, "checkout", atev_dob);
                                send_wait(0, atev_dob, "cancel_me");
                                send_wait(0, group_leader, "checkin");
                                if (msg_error())
                                {
                                         logf(ERROR, "%s - error cancelling event for CO %s - %s", method, chg_ref_num, msg[0]);
                                }
                                else
                                {
                                        if (DEBUG) logf(SIGNIFICANT, "%s - successfully canceled event for CO %s", method, chg_ref_num);
                                }
                        }
                }
 
 
        ////////////////////////////////////////////////////////////////////////////////
        // Add events 50% and 75% of the duration time
        ////////////////////////////////////////////////////////////////////////////////
                if (DEBUG == 2) logf(SIGNIFICANT, "%s - Command executed in CO nº: %s to add event: %s - duration: %s - start_date  
%s",  method, chg_ref_num,event_name_50,(duration)duration_75,(date)schedule_start_date_new);
                send_wait(0,top_object(),"call_attr","evt","new_attached_event", group_leader,persistent_id,event_name_50,(duration)duration_50,(date)schedule_start_date_new,"INCPRI",0,0,"");
                if (msg_error())
                {
                        logf(ERROR, "%s - error new_attached_event failed for CO %s - %s",  method, chg_ref_num, msg[0]);
                }
                else
                {
                        if (DEBUG) logf(SIGNIFICANT, "%s - successfully new_attached_event for CO %s - %s",  method, chg_ref_num, msg[0]);
                }
 
 
 
                if (DEBUG == 2) logf(SIGNIFICANT, "%s - Command executed in CO nº: %s to add event: %s - duration: %s - start_date  
%s",  method, chg_ref_num,event_name_75,(duration)duration_75,(date)schedule_start_date_new);
                send_wait(0,top_object(),"call_attr","evt","new_attached_event", group_leader,persistent_id,event_name_75,(duration)duration_75,(date)schedule_start_date_new,"INCPRI",0,0,"");
                if (msg_error())
                {
                        logf(ERROR, "%s - error new_attached_event failed for CO %s - %s",  method, chg_ref_num, msg[0]);
                }
                else
                {
                        if (DEBUG) logf(SIGNIFICANT, "%s - successfully new_attached_event for CO %s - %s",  method, chg_ref_num, msg[0]);
                }
 
 
                send_wait(0, group_leader, "checkin");
                if (msg_error())
                {
                        logf(ERROR, "%s - Add event checkin failed for CO %s - %s",  method, chg_ref_num, msg[0]);
                        send_wait(0, group_leader, "uncheck");
                }
                else
                {
                        if (DEBUG == 2) logf(SIGNIFICANT, "%s - Add event checkin successfull CO %s - %s",  method, chg_ref_num, msg[0]);
                }
        }
        if (DEBUG) logf(SIGNIFICANT,"=========== END : %s %s:%s ===========",method,type,chg_ref_num);
 
}
This page was last modified 09:46, 11 February 2011.  This page has been accessed 2,309 times.  Content is available under Attribution-Noncommercial-Share Alike 3.0 UnportedDisclaimers