CA Service Management

  • 1.  Make Attachment Required For Some Categories

    Posted Feb 19, 2018 05:26 AM

    Is it possible to prevent creating requests without an attachment for some request areas?

    I tried the below:

     

    mod file will be:

    MODIFY cr POST_VALIDATE z_req_attmnt() 1000 FILTER (EVENT("INSERT"));

    spl file:

    cr::z_req_attmnt(...) {     if (category == "pcat:5109") {          send_wait(0, top_object(), "call_attr", "lrel_attachments_requests", "sync_fetch", "STATIC", format("cr = '%s'", persistent_id), -1, 0);          if (msg[1] == 0) {               set_error(1);               set_return_data(format("Attachments are required for [%s] area", category.sym));               return;          }     }}

    but it doesn't seem to be working, because the alert is displayed even if a file is attached.

     

    i believe that there is something missing in the spl file

    so appreciate your feedback.

     

    Mohamed El-Fahd



  • 2.  Re: Make Attachment Required For Some Categories

    Posted Feb 19, 2018 08:15 AM

    shall i update any values on employee pages and especially in detail_cr



  • 3.  Re: Make Attachment Required For Some Categories

    Posted Feb 19, 2018 11:00 AM

    Hello m.fahd,

     

    OOTB its not possible, but you could create some field in the request area object like a flag for example "zcheck_request_attachment" and through SPL you could check this flag and avoid to save request if there is not an attachement added.

     

    Regards,



  • 4.  Re: Make Attachment Required For Some Categories

    Posted Feb 20, 2018 02:52 AM

    HI Yona;

     

    i already did this part but what i cannot is whether i attach the file or not the message keep saying that i must attach a file.

     

    Best Regards;

     

    Mohamed El-fahd



  • 5.  Re: Make Attachment Required For Some Categories

    Posted Feb 20, 2018 08:07 AM

    any updates please??



  • 6.  Re: Make Attachment Required For Some Categories

    Posted Feb 20, 2018 12:19 PM

    It takes a bit of work to do this, but it's kind of like this ...
    You will have to create a PRE_VALIDATE trigger on the object 'lrel_attachments_requests' which should be executed with a sequence preceding the PRE_VALIDATE trigger of the 'cr' object. When this LREL trigger is executed, you will have to persist in the 'cr' object with the attachment information. This can be done through a LOCAL attribute on the 'cr' object.
    Finally, the PRE_VALIDATE trigger of the 'cr' object will check the contents of this LOCAL attribute, and will not proceed with the save if the attachment is not associated.



  • 7.  Re: Make Attachment Required For Some Categories

    Posted May 11, 2018 08:57 AM

    Can you please post an example of this approach using LOCAL attribute



  • 8.  Re: Make Attachment Required For Some Categories

    Posted May 11, 2018 09:48 AM
    // in z_chg.mod
    OBJECT lrel_asset_chgnr {
         TRIGGERS {
                   PRE_VALIDATE z_chg_adiciona_remove_ic( chg, nr ) 2000 FILTER EVENT ("INSERT DELETE");
                   };
    };

    OBJECT chg {
         ATTRIBUTES Change_Request {
                   z_loc_add_nr_persids     LOCAL STRING;
                   z_loc_remove_nr_persids     LOCAL STRING;
         };
         
         TRIGGERS {
                   PRE_VALIDATE z_chg_valida_ticket( persistent_id, assignee, z_srl_Assignee_2, z_srl_Assignee_3, z_srl_Assignee_4, sched_start_date, sched_duration, z_loc_add_nr_persids, z_loc_remove_nr_persids ) 2010 FILTER EVENT ("INSERT UPDATE") && (assignee {} || z_srl_Assignee_2 {} || z_srl_Assignee_3 {} || z_srl_Assignee_4 {} || group {} || z_srl_Group_2 {} || z_srl_Group_3 {} || z_srl_Group_4 {} || sched_start_date {} || sched_duration {} || z_loc_add_nr_persids {} || z_loc_remove_nr_persids {});
              };
    };

    // in z_chg.spl
    lrel_asset_chgnr::z_chg_adiciona_remove_ic(...)
    {
         string zs_attribute;
         if (event() == 'INSERT') {
              zs_attribute = "chg.z_loc_add_nr_persids";
         
         } else if (event() == 'DELETE') {
              zs_attribute = "chg.z_loc_remove_nr_persids";
         }

         if (!is_empty(zs_attribute)) {
              string zs_value;
              zs_value = z_get_val(this, zs_attribute, zi_depurar, zs_metodo);
              
              if (zi_depurar > 1) logf(SIGNIFICANT, "%s (ANTES) PERSID's armazenados no atributo '%s': '%s'", zs_metodo, zs_attribute, zs_value);
              if (sindex(zs_value, nr.persistent_id) == -1) {
                   if (zi_depurar > 0) logf(SIGNIFICANT, "%s Armazenando o persid '%s' do IC...", zs_metodo, nr.persistent_id);
                   if (is_empty(zs_value)) {
                        z_changeValue(this, zi_depurar, zs_metodo, zs_attribute, format("%s", nr.persistent_id));
                   } else {
                        z_changeValue(this, zi_depurar, zs_metodo, zs_attribute, format("%s %s", zs_value, nr.persistent_id));
                   }
              }
              if (zi_depurar > 1) {
                   zs_value = z_get_val(this, zs_attribute, zi_depurar, zs_metodo);
                   logf(SIGNIFICANT, "%s (DEPOIS) PERSID's armazenados no atributo '%s': '%s'", zs_metodo, zs_attribute, zs_value);
              }
         }

        z_bloco_fim(zi_depurar, zs_metodo);
    }


    chg::z_chg_valida_ticket(...)
    {
         int zi_depurar;
            zi_depurar = 1;

         int zi_attached_nr_count;
         zi_attached_nr_count = asset.length;
         string zs_attached_nr_persids, zs_all_nr_persids;
         zs_attached_nr_persids = '';
         zs_all_nr_persids = '';
         if (zi_depurar > 0) logf(SIGNIFICANT, "%s Quant. de IC's associados na mudanca '%s': %d", zs_metodo, zs_persid, zi_attached_nr_count);

         // Identifica os IC's ja existentes na mudanca
         if (zi_attached_nr_count > 0) {
              string zs_asset;
              for (zi_i=0; zi_i<zi_attached_nr_count; zi_i++) {
                   zs_asset = format("asset.%d.persistent_id", zi_i);
                   send_wait(0, this, "call_attr", zs_asset, "get_val");
                   if (msg_error()) {
                        zs_msg = format("%s ERRO ao consultar o atributo '%s' do objeto '%s': '%s'", zs_metodo, zs_asset, zs_persid, msg[0]);
                        logf(ERROR, "%s", zs_msg);
                        z_bloco_fim(zi_depurar, zs_metodo);
                        return zs_msg;
                   }
                   zs_attached_nr_persids += format("%s ", msg[0]);
              }
              zs_all_nr_persids = zs_attached_nr_persids;
         }
         
         // Identifica os IC's recentemente adicionados na mudanca
         if (!is_empty(z_loc_add_nr_persids)) {
              zs_all_nr_persids += z_loc_add_nr_persids;
         }

         // Identifica os IC's recentemente removidos na mudanca
         if (!is_empty(z_loc_remove_nr_persids)) {
              zs_all_nr_persids = z_remove_itens(zs_all_nr_persids, z_loc_remove_nr_persids, ' ', zi_depurar, zs_metodo);
         }
         zs_all_nr_persids = z_Trim(zs_all_nr_persids);

         if (zi_depurar > 0) {
              logf(SIGNIFICANT, "%s IC's associados : '%s'", zs_metodo, zs_attached_nr_persids);
              logf(SIGNIFICANT, "%s IC's adicionados: '%s'", zs_metodo, z_loc_add_nr_persids);
              logf(SIGNIFICANT, "%s IC's removidos  : '%s'", zs_metodo, z_loc_remove_nr_persids);
              logf(SIGNIFICANT, "%s IC's (TODOS)    : '%s'", zs_metodo, zs_all_nr_persids);
         }

         // Armazena todos os persids dos IC's em um ARRAY
         string zs_nr_persid[100];
         int zi_nr_count, zi_priority_nr_major;
         zi_priority_nr_major = 0;

         zi_nr_count = split(zs_nr_persid, zs_all_nr_persids, ' ');
         if (zi_depurar > 0) logf(SIGNIFICANT, "%s Quantidade de IC's identificados: %d", zs_metodo, zi_nr_count);

         if (zi_nr_count == 0) {
    if (zi_depurar > 0) logf(SIGNIFICANT, "%s AVISO: NAO existem IC's associados a esta mudanca.", zs_metodo);
              zs_msg += format("Itens de configuracao: No minimo um IC precisa estar associado a mudanca.<br>");
         }
         
         //////////////////////////////////////////
         // EXIBICAO DA MENSAGEM DE ERRO
         //////////////////////////////////////////
    if (!is_empty(zs_msg)) {
              logf(ERROR, "%s %s", zs_metodo, zs_msg);
              set_error(1);
              set_return_data(zs_msg);
         }

        z_bloco_fim(zi_depurar, zs_metodo);
        return;
    }


    string z_get_val(object zo_object, string zs_attr, int zi_depurar, string zs_metodo) {

         zs_metodo += ' z_get_val';
         string zs_msg;
         
         send_wait(0, zo_object, "call_attr", zs_attr, "get_val");
         if (msg_error()) {
              zs_msg = format("%s ERRO ao consultar o atributo '%s' do objeto '%s': %s", zs_metodo, zs_attr, zo_object.persistent_id, msg[0]);
              logf(ERROR, "%s", zs_msg);
              z_bloco_fim(zi_depurar, zs_metodo);
              return zs_msg;
         }
         if (zi_depurar > 0) logf(SIGNIFICANT, "%s Valor do atributo '%s' no objeto '%s': '%s'", zs_metodo, zs_attr, zo_object.persistent_id, (string) msg[0]);

         return msg[0];
         // Fim do codigo
         ///////////////////////////////////     
    }


    string z_changeValue(object zo_obj, int zi_depurar, string zs_metodo, ...)
    {
         zs_metodo += " z_changeValue";

         int zi_i;
         for (zi_i=3; zi_i<argc; zi_i+=2) {
              if (zi_depurar > 0) logf(SIGNIFICANT, "%s Persistindo valor '%s' no atributo '%s'...", zs_metodo, argv[zi_i+1], argv[zi_i]);
              send_wait(0, zo_obj, "call_attr", argv[zi_i], "set_val", argv[zi_i+1], "SURE_SET");
              if (msg_error()) {
                   logf(ERROR, "%s ERRO ao persistir o valor '%s' no atributo '%s': '%s'", zs_metodo, argv[zi_i+1], argv[zi_i], msg[0]);
                   return msg[0];
              }
         }
         return;
    }


  • 9.  Re: Make Attachment Required For Some Categories

    Posted May 11, 2018 12:33 PM

    Here is my modified code for this scenario that works in my environment

    // in z_cr.mod

     

    OBJECT lrel_attachments_requests {
    TRIGGERS {
    PRE_VALIDATE z_cr_attmnt() 2000 FILTER EVENT ("INSERT");
    };
    };

    OBJECT cr {

    ATTRIBUTES Call_Req {
    z_has_attachment LOCAL INTEGER;

    };
    TRIGGERS
    {
    PRE_VALIDATE z_cr_check_attachment( persistent_id, z_has_attachment ) 2010 FILTER EVENT ("INSERT");
    };
    };

     

    // in z_cr.spl

     

    string z_changeValue(object zo_obj, ...)
    {
    int zi_i;
    for (zi_i=1; zi_i<argc; zi_i+=2) {
    send_wait(0, zo_obj, "call_attr", argv[zi_i], "set_val", argv[zi_i+1], "SURE_SET");
    if (msg_error()) {
    return msg[0];
    }
    }
    return;
    }

    lrel_attachments_requests::z_cr_attmnt(...)
    {
    z_changeValue(this, "cr.z_has_attachment", 1);
    }


    cr::z_cr_check_attachment(...)
    {
    string error_messsage;
    if(category=="pcat:5109")
    if(is_empty(z_has_attachment))
    {
    error_messsage = format("For the category %s  attachment is required", category.sym);
    set_error(1);
    set_return_data(error_messsage);
    }
    }