CA Service Management

  • 1.  Help on SPEL Code

    Posted Jul 27, 2017 12:08 PM

    Hey guys,

     

    First of all, i apologize for not being so familiar with SPEL codes, this is one of my first attempts to perform a customization using these triggers.

     

    Well, in this time, i need to find a way to change the status of all child tickets based on a predefined condition.

     

    For this, after some researches, i was able to structure this code that, in my little understanding, would be able to change the status of all children tickets.

     

    cr::zaprove_child(...){
    uuid who;
    string wc;
    int c_count, i;
    object c_dob, c_list;
    wc = format("parent = 'cr:%s' AND active = 1");     
    send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "MLIST_STATIC", wc, -1, 0);
    c_list = msg[0];
    c_count = msg[1];
    if (c_count > 0) {
    for(i=0; i<c_count; i++) {
    send_wait(0, c_list, "dob_by_index", "DEFAULT", i, i);
    c_dob = msg[0];
    who=msg[0];
    send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, c_list, "Status alterado via SPEL Code", "crs:40001");
    }
    if (msg_error()) {
    logf(ERROR, "Error changing child status", msg[0]);
    } else {
    logf(SIGNIFICANT, "Successfully changing child status");
    }
    }
    }

     

    To test the customization I triggered the file as follows:

     

    TRIGGERS {
       POST_VALIDATE zaprove_child(child)  18 FILTER (EVENT("UPDATE") && (parent != NULL));
       };

     

    My client requested that this action be executed when clicking on a button in the parent ticket, i also imagined that, when I finish the entire structure of my SPEL code, cause the action to be triggered by clicking a button, simliar to the closse_all_child function ina button:

     

    ImgBtnCreate("btn001", "Fechar todos os filhos", "pdm_submit('main_form','CLOSE_ALL_CHILD')", true, 120);

     

    In the stdlog file the following error message is displayed when I create a ticket and associate it with a parent

     

    spelsrvr            18100 ERROR        pdm_misc.pm            106 Error doing auto_find_assignee AHD05451:cr:513951 Nenhum Grupo qualificado encontrado
    spelsrvr            18100 ERROR        pcexec.c              6403 Spell interp failed at bopevt.spl:1243:atev::compute_next_time | bopevt.spl:1021:atev.wait_time::post_val10: AHD04324:Erro na linha 1 coluna 1 da definição. AHD04321:Especificação de data inválida. Linha de erro:0
    web:local           19108 ERROR        freeaccess.spl        3339 AHD04410:Não é possível encontrar o tipo de dados para o atributo cr from_request
    spelsrvr            18100 ERROR        pdm_misc.pm            106 Error doing auto_find_assignee AHD05451:cr:513952 Nenhum Grupo qualificado encontrado

     

    Have any of you ever had to do something like that?

     

    Thanx for the help!



  • 2.  Re: Help on SPEL Code

    Posted Jul 28, 2017 02:37 AM

    Hi,

    I really didn't catch your goal... Regarding to parent-child relation there is few common scenarios like:

    - close all childs when parent being resolved (I prefer closed);

    - close parent when all childs are resolved;

    also it's possible to call SPEL from button but you need to implement custom webengine op (more info: SPEL: Register custom webengine OP).

     

    Moving next to your code:

    TRIGGERS {
       POST_VALIDATE zaprove_child(child)  18 FILTER (EVENT("UPDATE") && (parent != NULL));
       };

    here you passing child as argument but script do not handle it, then regarding to defined filter your script will fire on every request update such as Log comment, tranfser, status change, summary update, etc...

     

    In a function:

    - line6: you missed argument in format, example:

    format("parent = '%s' AND active = 1 AND status != '%s'", persistent_id, status);

    - line7: no error handling like presented on line17, if error happens, it can cause spel_srvr failure which can harm entire sdm service;

     

    If you provide a little more information about your goal I hope I (or someone else) could provide a code adapted to your needs.

     

    Regards,

    cdtj



  • 3.  Re: Help on SPEL Code

    Posted Jul 28, 2017 11:08 AM

    Hi, cdtj!

     

    Many thanx for answering and sorry if I could not be so clear!

     

    Well, i need to create a button on the parent ticket to change the status of all children to a custom status called "Approved."

     

    As I could not find some content of the "close_all_child" function that I could modify to change the status to "Approved" instead of closing all the children, i chose to do the customization using SPEL code.

     

    So, if the "$args.children.length" is not null, then the button "Approve all children" will be presented, clicking this button, all children will have their status changed to "Approved."

     

    I realized that the "child" argument does not really exist and SDM did not go up until I removed the attribute from trigger!

     

    Thanx for the SPEL: Register custom webengine OP  tip, i will do the customization!



  • 4.  Re: Help on SPEL Code

    Posted Sep 14, 2017 03:13 PM

    Hi cdtj!

     

    After some time of research and study I managed to reach some spel codes that helped me achieve some goals in other needs, the last one (also for community help) I was able to change the status of the parent ticket after all the child tickets were solved.

     

    However I'm still having a hard time doing the opposite, I've created some codes based on some research I've done, but I still have not been able to change the status of all children using the spel code below:

     

     

    cr::z_change_child_stat(...){
    string c_desc, c_num, c_statsym, wc;
    object c_dob, c_list;
    int c_count, i;
    wc = format("parent = 'cr:%s' AND status != '%s' AND active = 1");     // where clause
    send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "MLIST_STATIC", wc, -1, 0);
    c_list = msg[0];     // child record list
    c_count = msg[1];     // child record count
    if (c_count > 0) {
    for(i=0; i<c_count; i++) {
    send_wait(0, c_list, "dob_by_index", "DEFAULT", i, i);
    c_dob = msg[0];     // child database object
    send_wait(0, c_dob, "get_attr_vals", 2, "ref_num", "status.sym");
    c_num = msg[3];     // child record number
    c_statsym = msg[9];     // child status sym
    c_desc = c_desc + " (Test " +  + " " +  + ")" ;     // child alg.description
    send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, persiistent_id, "z_change_child_stat", "crs:5201");
    }
    }
    }

     

    I'm not sure if this spel code is correct or if the error is in the trigger.

     

    I'm using this trigger only to test if the spel code is working properly, my goal is to make this spel be run from a button (according to SPEL: Register custom webengine OP ):

     

    Trigger:

     

    OBJECT cr {
    TRIGGERS {
      POST_VALIDATE z_change_child_stat() 10029 FILTER( EVENT("INSERT UPDATE") && status{->'RE'} );
    };
    };

     

    Could you evaluate this spel code and verify that it is correct?

     

    I'll keep trying to make some modifications to this code and let you know if i can achieve the goal before your help!

     

    Many thanx again!!



  • 5.  Re: Help on SPEL Code

    Posted Sep 15, 2017 01:12 AM

    The typo in 'persiistent_id' won't help ☺

    Regards,

    James



  • 6.  Re: Help on SPEL Code

    Posted Sep 15, 2017 02:46 AM

    Hi,

    you missed arguments in line 5, line 16 and i think that lines 11-17 should be:

    send_wait(0, c_list, "dob_by_index", "DEFAULT", i, i);
    c_dob = msg[0];
    c_desc = format("Changing status from [%s] on [%s]", c_dob.status.sym, c_dob.ref_num);
    send_wait(0, top_object(), "call_attr", "api", "generic_status_change", who, c_dob.persistent_id, c_desc, "crs:5201");

    if you want to call it from button, this example would be helpful: https://www.facebook.com/groups/usuariossdmbrasil/permalink/1560001184030790/ 

    Regards,

    cdtj



  • 7.  Re: Help on SPEL Code

    Posted Jul 28, 2017 06:10 AM

    Hi.

    The startup in this area is not that easy, of course....
    Therfore, some general remarks/considerations from my side

     

    • There are always many roads to reach to the goal.
      Most of the application logic is based on "changing data", that means, application logic gets executed when changing data, in fact when saving changed data.
      If you have this kind of triggering event you could use the majic triggers together with spel code to achieve your goal
      In the last years this got very common to do so, even by customers directly. You will find a lot examples, how to do it. But you are on your own, meaning these kind of enhancements are not supported, and you rely on others when you get stuck.
    • If you want to have application logic triggered by a button click on the GUI you might go with the suggestion of cdtj introducing a new so called web operation, which leads to some executed spell code as well.
      Compared to the avbove approach, this is a not so common usage, and expirience in this area is even smaller than in the one above.
      Of course this is not supported officialy as well, even though I think, its a usefull and reliable possibility.

     

    As said before, there are always many different ways to implement solutions.
    For example, a button click can lead to a data change as well, and then you are back to the first (more common) approach.

     

    To get at least a bit more concrete, here are some ideas: In general: I would

    • introduce a local non persistent attribute to the ticket object for the ability
      of passing additional information (the child status) from the GUI to the server
    • You want to change data, so I would enable the button in the edit page of a
      parent ticket only.
    • the javascript executed by the button might ask the user for
      the appropriate new child status and then build an UPDATE url for the given
      parent ticket initiating a save and passing the code of the new cild status in
      the new local attribute
    • This will trigger a POST_CI trigger which then loops to all child tickets and set the status accordingly.

     

    This is more or less a common procedure for these kind of things, but it may not fit to your customer needs.

    Therefor cdtj asked for more details about the requirements.

     

    Hope this helps somehow.

     

    Kind regards

    .............Michael



  • 8.  Re: Help on SPEL Code

    Broadcom Employee
    Posted Sep 15, 2017 07:27 AM

    HI Diego,

     

    You might find this below communities link interesting for your future purpose, credit goes to TMACUL, GUTIS and a lot more the spell GURU's

     

    https://communities.ca.com/docs/DOC-231156196-where-can-i-find-spel-functions-documentation