Update Change Status based on Task Status using SPELL.

Document created by Fabiano Lopes Domingues on Mar 8, 2017Last modified by Fabiano Lopes Domingues on Mar 8, 2017
Version 2Show Document
  • View in full screen mode

Hello fellows,

Recently we were demanded to develop an automation to update the change status based on task status.

We decided to use SPELL despite ITPAM for many reasons (reliability,...).

We would like to share this code with the community and thank the information collected in Gutis, Daniel Bighelini and Thiago Macul posts. This informations were very helpfull to build the code.

There is others examples but we didn't found any spellcode that execute all our needs then we build our own.

We hope this doc helps others analysts and I let here my protests against absence of Spell Documentations by the CA.

 

Regards,

 

Mario.M.Gomes

fabiano.ldomingues

 

 

 

////////////////////////////////////////////////////////////////////////////
// Modulo [Module]:                   z_wf_atualiza_chg.spl
// Autor [Author]:                  Mario Machado Gomes & Fabiano L. Domingues
// Criado em [Created_dt]:          07/03/2017
// Modificado por [Mod_byby]:     Mario Machado Gomes & Fabiano L. Domingues
// Modificado em [Mod_dt]:         08/03/2017
//
////////////////////////////////////////////////////////////////////////////
//
// When the code is executed?
// The code is executed after a commit in WF table. You must to created or update the file wf.mod (NXROOT\site\mods\majic) as the following sample.
// MODIFY wf {POST_CI z_wf_atualiza_chg(status, comments, persistent_id, task, assignee, chg, sequence) 5000 FILTER (EVENT("UPDATE") && (sequence==1) &&((status=="AUTORIZADA") || (status=="REJ") || (status=="INFORMACOES")));};
//
//
wf::z_wf_atualiza_chg(...) {

// Trecho de código utilizado apenas para Troubleshooting. [used only for troubleshooting purposes].
// Faz a leitura das variáveis passadas por wf.mod e escreve no stdlog. [reads the variables from wf.mod and writes in stdlog files.]
int i;
int zDepurar;
zDepurar = 0;
if (zDepurar==1) {
for (i=0;i<argc;i+=1){
     logf(SIGNIFICANT, "argv[%d] = %s", i, argv[i]);
     }
}
//
// Declaração de variáveis  [Variables statement]
uuid who, super_user;
string zTask_Status, zTask_Comments, zTask_Persistent_id, zTask_Code, zTask_Assignee, zTask_Sequence, zTask_Assignee_Name, zChange_id, zChange_Persid, zAssignee_Query, zWF_Query, log;
//
// Coleta informações que serão utilizadas posteriormente nas operações de atualização do status da mudança" [Colects data for the update operations and logs.]
zTask_Status = argv[3];
zTask_Comments = argv[6];
zTask_Persistent_id = argv[9];
zTask_Code = argv[12];
zTask_Assignee = argv[15];
zAssignee_Query = "id = U'" + zTask_Assignee + "'";
zChange_id = argv[18];
zChange_Persid = "chg:" + zChange_id;
zTask_Sequence = argv[21];
zWF_Query = "chg = " + zChange_id + " and completion_date is null";
//
// Seleciona o usuário logado para execução das operações de atualização da Mudança. [Selects the logged user for update operations in selected RFC (Change)]
send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");
who=msg[0];
super_user = (uuid) "FAC835AE140C4E4CBFD719E511369652";  // Usuário ServiceDesk do Sistema [ServiceDesk User (admins user) do SDM.]
//
// Seleciona o Nome real do Responsável da Tarefa. [Selects the combo_name of the Assignee's Task.]
send_wait(0, top_object(), "call_attr", "api", "get_val_for_wc", "cnt", zAssignee_Query, "combo_name");    
zTask_Assignee_Name=msg[0];
//
// =================== OPERAÇÃO / OPERATIONS ============================================//
//
// Condição para setar variável de LOG e altera o status da Mudança. [Conditions to update RFC (Change) and generates log]
// O método find_msg localiza a mensagem customizada (63083) no arquivo pdm.xml. [find_msg method finds customized message in pdm.xml file]
// Sample line in pdm.xml: <msg id="63083"><text product_id="default">Message variable %1,  variable %2, variable %3....</text></msg>
//
if (zTask_Status == "AUTORIZADA") {
                              log = find_msg(63, 83, "AUTORIZOU sua execução.", zTask_Sequence, zTask_Comments, zTask_Assignee_Name, zTask_Status);
                              send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, zChange_Persid, log, "chgstat:6000"); 
                              }                              
else if (zTask_Status == "REJ") {
                              log = find_msg(63, 83, "REJEITOU sua execução.", zTask_Sequence, zTask_Comments, zTask_Assignee_Name, zTask_Status);
                              // Apaga as tarefas relacionadas à RDM que ainda estão ativas [deletes actives workflow tasks of the RFC.]
                              send_wait(0, top_object(), "call_attr", "api", "delete_wc", "wf", zWF_Query, NULL);
                              // Log sobre a exclusão das Tarefas ativas antes da Rejeição da RDM. [writes log in RFC to inform the deletion.]
                              send_wait(0, top_object(), "call_attr", "api", "generic_activity_log", super_user, zChange_Persid, "EXECUÇÃO DE AUTOMAÇÃO: todas as tarefas ativas desta RDM foram excluídas para permitir sua rejeição. (REF: z_wf_atualiza_chg)", "LOGSPELL", 0, 0);
                              // Altera status da RDM
                              send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, zChange_Persid, log, "chgstat:6013"); 
                          }
else if (zTask_Status == "INFORMACOES") {
                              log = find_msg(63, 83, "REQUISITOU MAIS INFORMAÇÕES ao solicitante.", zTask_Sequence, zTask_Comments, zTask_Assignee_Name, zTask_Status);
                              send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, zChange_Persid, log, "chgstat:6015"); 
                              send_wait(0, top_object(), "call_attr", "api", "generic_activity_log", who, zChange_Persid, zTask_Comments, "LOG", 0, 0);
                              
                         }
else {
                              logf(SIGNIFICANT,"Entrou no ELSE");
                              log = "Status da Tarefa do Gestor de Serviço alterada para um status sem interação com a Mudança";
                         }
//
// Registra no stdlog que este código foi executado. [Writes in stdlog this code execution]
logf(SIGNIFICANT, "O spell z_wf_atualiza_chg foi executado mediante atualização da Tarefa: %s", zTask_Persistent_id);
}


//=========================================== FIM / END ==================================================================//
2 people found this helpful

Attachments

    Outcomes