AnsweredAssumed Answered

Attach service type events on incidents

Question asked by GIPSI on May 19, 2017
Latest reply on May 23, 2017 by GIPSI

Hello,

 

I need help for this particular case.

 

We decided to attach service types with CI from class application.Those services types depend on incident priority and a custom incident field named zconcerned_application, which is linked to a custom factory zappl. On this factory, I created 4 custom fields zsla_p1, zsla_p2, zsla_p3 and zsla_p4, which contains a specific service type for the priority.

 

Based on what I've read on CA communities, I started to write this code :

 

////////////////////////////////////////////////////////////////////////
// Method:      cr::zcr_sla()
//
// Description: sets the service level of the call request based
//   on its current prority and its concerned_application
//
//    
// Input
//     priority                        = argv[3];
//  support_lev                     = argv[6];
//     zconcerned_application      = argv[9];
//  category                         = argv[12];
//  zenvironnementINC               = argv[15];
//
// Return
//   None
////////////////////////////////////////////////////////////////////////
cr::zcr_sla(...)
{
     logf(SIGNIFICANT, "%s: ref_num = %s", "cr::zcr_sla",(string)argv[15] );

// If no prority or concerned application change, return
     if ((argv[2] == argv[3]) && (argv[5] == argv[6]))
     return;

     string _category, _zenvironnementINC;
    
// Si catégorie différente de "Application/SVA", on sort
     send_wait(0, top_object(), "call_attr", "api", "get_val_for_wc", "pcat", format("persistent_id ='%s'",(string)argv[9]),"sym");
     if (msg_error()) {
          logf(ERROR, "Error for getting category symbol %s : ", msg[0]);
          return;
     }
     _category = msg[0];
         
     if (_category != "Application/SVA")
          return;
    

// If environment not "Production" or "Homologation", return
     send_wait(0, top_object(), "call_attr", "api", "get_val_for_wc", "zdata_environnementINC", format("id =%d",(string)argv[12]),"sym");
     if (msg_error()) {
          logf(ERROR, "Error for getting zenvironnementINC symbol %s : ", msg[0]);
          return;
     }
     _zenvironnementINC = msg[0];

     if (_zenvironnementINC != "Production" && _zenvironnementINC != "Homologation")
          return;

     string ,_priority, _zconcerned_application;

     _priority = (string)argv[3];
     _zconcerned_application = (string)argv[6];
    
     string new_sla;
     string zapp_persid;
     string zsla_p1,zsla_p2,zsla_p3,zsla_p4;
     
     if(_priority == "1") {
          send_wait(0, top_object(), "call_attr", "api", "get_val_for_wc", "zappl", format("id=U'%d'",_zconcerned_application),"zsla_p1");

          if (msg_error()) { 
            logf(ERROR, "Error for getting zconcerned_application sla %s",msg[0]); 
          } 
          else  {
               new_sla = msg[0];
          }
     }
     else {
          if(_priority == "2") {
               send_wait(0, top_object(), "call_attr", "api", "get_val_for_wc", "zappl", format("id =U'%s'",_zconcerned_application),"zsla_p2");

               if (msg_error()) { 
                 logf(ERROR, "Error for getting zconcerned_application sla %s",msg[0]); 
               } 
               else  {
                    new_sla = msg[0];
               }
          }
          else {
               if(_priority == "3") {
                    send_wait(0, top_object(), "call_attr", "api", "get_val_for_wc", "zappl", format("id =U'%s'",_zconcerned_application),"zsla_p3");

                    if (msg_error()) { 
                      logf(ERROR, "Error for getting zconcerned_application sla %s",msg[0]); 
                    } 
                    else  {
                         new_sla = msg[0];
                    }
               }
               else {
                    send_wait(0, top_object(), "call_attr", "api", "get_val_for_wc", "zappl", format("id =U'%s'",_zconcerned_application),"zsla_p1");

                    if (msg_error()) { 
                      logf(ERROR, "Error for getting zconcerned_application sla %s",msg[0]); 
                    } 
                    else  {
                         new_sla = msg[0];
                    }
               }
          }
     }    

     uuid who; 
     object newobject; 
     string zattached_sla;
     send_wait(0,top_object(), "call_attr", "cnt", "current_user_id"); 
     who=msg[0];
     string cr_persid,cr_id;
     cr_persid = argv[21];
     cr_id = substr(cr_persid,3,strlen(cr_persid));
     logf(SIGNIFICANT, "cr_id %s - cr_persid %s", cr_id, cr_persid); //log new object id 
     send_wait(0, top_object(), "call_attr", "api", "insert_object", who, "attached_sla", NULL, 0, "map_sdsc", new_sla, "ticket_id", cr_id, "ticket_type", "cr", "_mapped_cr", cr_persid); 
     if (!msg_error()) { 
          newobject = msg[0]; 
          zattached_sla = newobject.id;
          logf(SIGNIFICANT, "new attached_sla id %s", zattached_sla); //log new object id 
          cr::add_attached_events(new_sla,cr_persid,zattached_sla,who);
     } 
}

cr::add_attached_events(string service_type, string cr_persid, string attached_sla, uuid who) {
     logf(SIGNIFICANT, "cr::add_attached_event %s", service_type); //log new object id

     int count; 
     string _event;
    
// Get service type events list
     send_wait(0, top_object(), "call_attr", "api", "get_list", "slatpl", who, format("service_type='%s'",service_type), -1);  
     if (msg_error()) {  
          logf(SIGNIFICANT,"Error %s",msg[0]);  
     }  
     else { 
          object obList; 
          count = msg[1]; 
          obList = msg[0]; 
          logf(SIGNIFICANT, "nb event %d",count); 
          send_wait(0, top_object(), "call_attr", "api", "get_list_values", who, obList,0,count,0,"event");  
          if (msg_error())  
               logf(SIGNIFICANT,"Error %s",msg[0]);  
          else { 
               int i;  
          // For each event, attach it to incident
               for (i=0;i<msg_length();i++) {  
                    i=i+2;
                    _event = msg[i];
                    logf(SIGNIFICANT,"Event[%d]: '%s' on %d", i, _event,msg_length());
                   
                    object Objevt; 
                    send_wait(0, top_object(), "call_attr", "evt", "dob_by_persid", 0, _event); 
                    if (msg_error()) { 
                         logf(SIGNIFICANT,"Error %s",msg[0]); 
                    } 
                    else 
                    { 
                         Objevt = msg[0]; 
                         send_wait(0, top_object(), "call_attr", "evt", "new_attached_event_obj", NULL, cr_persid,Objevt, Objevt.delay_time,(date) NULL, "SLA", 0, 0,""); 
                         if (msg_error()) { 
                              logf(SIGNIFICANT,"Error %s",msg[0]); 
                         } 
                    }
               }  
          } 
     } 
}

 

The result is that the service type event is well attached to the incident, as the first event attached to this service type, but the other events do not, and I don't know why...

 

The for loop on line 145 is just executed one time, even if there are more events to attach.

 

The only I have is :

05/19 11:22:17.78 WIDV179A       spelsrvr            28156 ERROR        sla.spl               3734 Error checking in deleted atev: Attempt to checkin with nothing checked out.
05/19 11:22:17.81 WIDV179A       spelsrvr            28156 SIGNIFICANT  gipsi_cr.spl           322 cr::zcr_sla: ref_num = 369970
05/19 11:22:17.95 WIDV179A       spelsrvr            28156 SIGNIFICANT  gipsi_cr.spl           427 cr_id 769900 - cr_persid cr:769900
05/19 11:22:18.14 WIDV179A       spelsrvr            28156 SIGNIFICANT  gipsi_cr.spl           432 new attached_sla id 487781
05/19 11:22:18.14 WIDV179A       spelsrvr            28156 SIGNIFICANT  gipsi_cr.spl           438 cr::add_attached_event sdsc:400003
05/19 11:22:18.16 WIDV179A       spelsrvr            28156 SIGNIFICANT  gipsi_cr.spl           452 nb event 5
05/19 11:22:18.17 WIDV179A       spelsrvr            28156 SIGNIFICANT  gipsi_cr.spl           462 Event[2]: 'evt:400059' on 15
05/19 11:22:18.28 WIDV179A       spelsrvr            28156 SIGNIFICANT  gipsi_cr.spl           322 cr::zcr_sla: ref_num = 369970

 

Could someone explain this behavior to me please ?

Outcomes