AnsweredAssumed Answered

Issue with attached SLA

Question asked by GIPSI on Jun 12, 2017
Latest reply on Jun 19, 2017 by Michael Mueller

Hello,

 

I wrote a spel to attach SLA to incident based on priority and a custom application field, which is below.

 

It works great, but we have an issue when transferring to another group. The attached events are cancelled, and the attached sla is completely deleted, including in the database.

 

And I do not have any clue about which code can cause this ...

 

Does anyone have any idea what might happen?

 

 

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

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

     string _category, _zenvironnementINC;
     
// If category different of "Application/SVA", return
     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 different of "Production" and "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'%s'",_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_p4");

                    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[18];
     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;
     object group_leader; 
     send_wait(0, top_object(), "get_co_group"); 
    if (msg_error()) { 
          logf(SIGNIFICANT,"Error'%s'", msg[0]); 
          return; 
    } 
     else{ 
          group_leader = msg[0]; 
     }
// Get event list linked to the service type
     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;  
               count = 0;
               string event_persid_list[30];
               for (i=2;i<msg_length();i=i+3) {
                    event_persid_list[count]=msg[i];
                    logf(SIGNIFICANT,"msg[%d]: %s", i, msg[i]);
                    logf(SIGNIFICANT,"event_persid_list[%d]: %s", count, event_persid_list[count]);
                    count++;
               }
          // For each event, attach it to the incident
               for (i=0;i<count;i++) {  
                    logf(SIGNIFICANT,"msg[%d]: %s", i, event_persid_list[i]);
               
                    _event = event_persid_list[i];
                    logf(SIGNIFICANT,"Event[%d]: '%s' on %d", i, _event,count);
                    
                    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]); 
                    }
                    
               }

               // Get attached events list
               send_wait(0, top_object(), "call_attr", "api", "get_list", "atev", who, format("obj_id='%s'",cr_persid), -1);  
               if (msg_error()) {  
                    logf(SIGNIFICANT,"Error %s",msg[0]);  
               }  
               else { 
                    count = msg[1]; 
                    obList = msg[0]; 
                    string atev_persid_list[30];
                    logf(SIGNIFICANT, "nb event to update %d",count); 
                    send_wait(0, top_object(), "call_attr", "api", "get_list_values", who, obList,0,count,0,"persistent_id");  
                    if (msg_error())  
                         logf(SIGNIFICANT,"Error %s",msg[0]);  
                    else { 
                         count = 0;
                         for (i=0;i<msg_length();i=i+3) {
                              atev_persid_list[count]=msg[i];
                              logf(SIGNIFICANT,"atev_persid_list[%d]: %s", i, atev_persid_list[i]);
                              count++;
                         }
                         for (i=0;i<count;i++) {
                              send_wait(0, top_object(), "call_attr", "api", "update_object", who, atev_persid_list[i], NULL, NULL, 0, "owning_ast", attached_sla);   
                              if (msg_error()) 
                                   printf("create failed %s",msg[0]);   
                              else
                                   logf(SIGNIFICANT,"atev %s updtated", i, atev_persid_list[i]);
                         }
                    }
               }
          }
     }
}

Outcomes