CA Service Management

Expand all | Collapse all

PreSaveTrigger - Type and Rootcause

  • 1.  PreSaveTrigger - Type and Rootcause

    Posted May 30, 2017 10:36 AM
      |   view attached

    Hi guys,

    I've to create a PreSaveTrigger to control the type of the ticket and the rootcause filled by the analysts.

    I've created the followed rootcauses:

    If the ticket is an incident then the rootcause starts with INC.%

    If the ticket is a request then the rootcause starts with SOL.%

     

    What I need to do is create a PreSaveTrigger to prevent the analysts don't save the tickets with wrong rootcause, just like:

    Request with rootcause starts with INC.% and Incident with rootcause starts with SOL.%

    I already have on my detail_in.htmpl a PreSaveTrigger created to control the description lenght, code is:

    function preSaveTrigger()
    {
        if ( _dtl.edit) {

        AlertMsg = "";
        var f = document.main_form;

        //Verifica se a descrição tem mais de 5 caracteres
        var zs_descricao = "SET.description";
        if (typeof f.elements[zs_descricao] != "undefined") {
            if (f.elements[zs_descricao].value.length < 5) {
                detailReportValidation(f.elements[zs_descricao], 1, "A descrição deve conter no mínimo 5 caracteres");
            } else {
                detailReportValidation(f.elements[zs_descricao], 0, "");
            }
        }

        if (AlertMsg != "") {
            showAlertMsg(false, false);
            return false;
        } else {
            return true;
            }
        }
    }

     

    I need to change this code, or create a new one?

    How can I do to prevent this case?

     

     



  • 2.  Re: PreSaveTrigger - Type and Rootcause

    Posted May 30, 2017 10:40 AM

    I believe this is for CA Service Desk Manager or CA Service Management and not Cloud Service Management. I will request that this is moved to the proper community.



  • 3.  Re:  PreSaveTrigger - Type and Rootcause

    Broadcom Employee
    Posted May 30, 2017 11:21 AM

    Thiago, if I were you I would modify the function preSaveTrigger2() instead of function preSaveTrigger(). Currently this

    function simply returns the value:

    function preSaveTrigger2()
    {
    return ok_to_save;
    }

    and you could modify to add if...then..else etc here.

    2cents for your consideration. Thanks _Chi



  • 4.  Re:  PreSaveTrigger - Type and Rootcause

    Posted May 30, 2017 01:33 PM

    Hi Chi Chen,

     

    My doubt is the code, which I should use to prevent this?



  • 5.  Re:  PreSaveTrigger - Type and Rootcause

    Posted May 31, 2017 03:04 AM

    Hi,

    as I understand your requirements, why not just to predefine rootcauses on HTMPL level?

    Regarding to your screenshot, are you using same form for incidents and requests?

    <PDM_IF "$args.type" == "R">
      <PDM_MACRO name=dtlLookup hdr="Rootcause" attr=rootcause extraURL="QBE.IN.sym=REQ.%">
    <PDM_ELIF "$args.type" == "I">
      <PDM_MACRO name=dtlLookup hdr="Rootcause" attr=rootcause extraURL="QBE.IN.sym=INC.%">
    <PDM_ELSE>
      <PDM_MACRO name=dtlLookup hdr="Rootcause" attr=rootcause>
    </PDM_IF>

    Or you selecting ticket type while creating it?

     

    Regards,

    cdtj



  • 6.  Re:  PreSaveTrigger - Type and Rootcause

    Posted May 31, 2017 05:55 AM

    Hi my friend,

    Thank you for your help once again.

     

    Yes, they select the ticket type while they are creating it.

    The attr is "zType2".

     

    I've edited the code that you send to me to my enviroment, just like this:

     

    <PDM_IF "$args.zType2" == "R">
    <PDM_MACRO name=dtlLookup hdr="Rootcause" attr=rootcause extraURL="QBE.IN.sym=SOL.%">
    <PDM_ELIF "$args.zType2" == "I">
    <PDM_MACRO name=dtlLookup hdr="Rootcause" attr=rootcause extraURL="QBE.IN.sym=INC.%">
    <PDM_ELSE>
    <PDM_MACRO name=dtlLookup hdr="Rootcause" attr=rootcause>
    </PDM_IF>

     

    When I try to use, I received an error message: Bad argument, just like the print attached.

     

    I've only 2 rootcauses created: 

    SOL.SOFTWARES.INSTALACAO
    INC.SOFTWARES.SERVICO INDISPONIVEL



  • 7.  Re:  PreSaveTrigger - Type and Rootcause

    Posted May 31, 2017 06:07 AM

    Your more thing that I identified on my tests.

     

    When I leave the field "zType2" in blank (NULL), then appear "list_rc" instead of hiersel_rc form.



  • 8.  Re:  PreSaveTrigger - Type and Rootcause

    Posted May 31, 2017 06:46 AM

    As far as I know there is a lot of problem to change search criteria of dtlLookup or dtlHier dynamically, for that purposes I use dtlDropdown's which can be filled by preloaded values on-the-go.

     

    Here is an example that should work in your scenario:

    function statusReloadRC(value) {
         var setRC = document.getElementsByName('SET.rootcause')[0];
         setRC.options.length = 0;
         setRC.options[0] = new Option("<Empty>", "", true, false);     
         var i=1;
         if (value == "I") {
              <PDM_LIST PREFIX=list WHERE="sym like 'INC.%' AND delete_flag = 0" FACTORY=rc>
                   setRC.options[i] = new Option("$list.sym", "$list.id", false, false);
                   i++;
              </PDM_LIST>
         } else if (value == "R") {
              <PDM_LIST PREFIX=list WHERE="sym like 'SOL.%' AND delete_flag = 0" FACTORY=rc>
                   setRC.options[i] = new Option("$list.sym", "$list.id", false, false);
                   i++;
              </PDM_LIST>
         } else {
              <PDM_LIST PREFIX=list WHERE="delete_flag = 0" FACTORY=rc>
                   setRC.options[i] = new Option("$list.sym", "$list.id", false, false);
                   i++;
              </PDM_LIST>
         }
    }

    <PDM_MACRO name=dtlDropdown hdr="Type" attr="zType2" evt="onChange=\\\"statusReloadRC(this.value)\\\"" lookup=no>
    <PDM_MACRO name=dtlDropdown hdr="Rootcause" attr="rootcause" lookup=no>

     

    I really don't like preSaveTrigger functionallity, because system shouldn't allow to input invalid values and that errors are really annoying because I'm sure that I filled everything correct. But if in your case you can't avoid it, code could be:

    function zCompareRCandType() {
         var rcInput = document.getElementsByName('KEY.rootcause')[0];
         var typeInput = document.getElementsByName('SET.zType2')[0];
         alert('Checking:\n\tType: ' + typeInput + '\n\tRootcause:' + rcInput);
         if (typeInput == 'I') {
              if (rcInput.indexOf('INC.') == -1)
                   return false;
         } else if (typeInput == 'R') {
              if (rcInput.indexOf('SOL.') == -1)
                   return false;
         }
         return true;
    }

    function preSaveTrigger() {
         if (!zCompareRCandType()) {
              alert('Please, select valid rootcause');
              return false;
         }
        if ( _dtl.edit) {
              // your old code goes here

    If checking will be failed, could you provide meesage from alert in line 4?

     

    PS: are we really talking about zType2 which is SREL to crt factory and rootcause which is SREL to rc factory?

     

    Regards,

    cdtj



  • 9.  Re:  PreSaveTrigger - Type and Rootcause

    Posted May 31, 2017 08:31 AM

    Yes, sure.

    zType2 is a SREL of CRT and rootcause to RC factory, that's right.

     

    I think I can't use dtlDropdown for this case, because on production enviroment, I've more than 1500 rootcauses. =(

     

    I already have one event attached on zType2 list:

    <PDM_MACRO name=dtlDropdown hdr="Tipo de chamado" attr="zType2" evt="onChange='zCheckVisibility(this)';">

     

    Can I attach one more event to this Dropdown?

     

     

    So there's no way to create a search criteria to hiersel_rc? =(

     

     



  • 10.  Re:  PreSaveTrigger - Type and Rootcause

    Posted May 31, 2017 08:33 AM

    Using function:

    zCompareRCandType

     

    Which old code that you refer?



  • 11.  Re:  PreSaveTrigger - Type and Rootcause

    Posted Jun 01, 2017 01:15 AM

    as you already have preSaveTrigger, you need to insert new function into it:

    function zCompareRCandType() {
         var zRCs = document.getElementsByName('KEY.rootcause');
         var zT2s = document.getElementsByName('SET.zType2');
         var zInfo = "";
         for (var i=0; i < zRCs.length; i++) {
              if (typeof(zRCs[i]) == "object") {
                   zInfo += i + ">\n\tname: " + zRCs[i].name + "\n\tvalue: " + zRCs[i].value + "\n\n";
              } else {
                   zInfo += i + ">\n\tis not an object: " + typeof(zRC[i]) + "\n\n";
              }
         }
         for (var i=0; i < zT2s.length; i++) {
              if (typeof(zT2s[i]) == "object") {
                   zInfo += i + ">\n\tname: " + zT2s[i].name + "\n\tvalue: " + zT2s[i].value + "\n\n";
              } else {
                   zInfo += i + ">\n\tis not an object: " + typeof(zT2s[i]) + "\n\n";
              }
         }
         alert(zInfo);
         return false;
    /*
         var rcInput = document.getElementsByName('KEY.rootcause')[0];
         var typeInput = document.getElementsByName('SET.zType2')[0];
         if (typeof (rcInput) == "undefined") {
              alert('Unable to fetch Rootcause');
              return false;
         } else if (typeof (typeInput) == "undefined") {
              alert('Unable to fetch Type');
              return false;
         }
         alert('Checking:\n\tType: ' + typeInput.value + '\n\tRootcause:' + rcInput.value);
         if (typeInput.value == 'I') {
              if (rcInput.value.indexOf('INC.') == -1)
                   return false;
         } else if (typeInput.value == 'R') {
              if (rcInput.value.indexOf('SOL.') == -1)
                   return false;
         }
         return true;
    */

    }

    function preSaveTrigger() {
        if (!zCompareRCandType()) {
            alert('Please, select valid rootcause');
            return false;
        }
        if (_dtl.edit) {
            AlertMsg = "";
            var f = document.main_form;
            //Verifica se a descrição tem mais de 5 caracteres
            var zs_descricao = "SET.description";
            if (typeof f.elements[zs_descricao] != "undefined") {
                if (f.elements[zs_descricao].value.length < 5) {
                    detailReportValidation(f.elements[zs_descricao], 1, "A descrição deve conter no mínimo 5 caracteres");
                } else {
                    detailReportValidation(f.elements[zs_descricao], 0, "");
                }
            }
            if (AlertMsg != "") {
                showAlertMsg(false, false);
                return false;
            } else {
                return true;
            }
        }
    }

     

    Also you can try to use Data Partition for CREATE/UPDATE actions:

    (zType2 = 'I' AND rootcause like 'INC.%') OR
    (zType2 = 'R' AND rootcause like 'SOL.%') OR
    (zType2 is NULL)

     

    Regards,

    cdtj



  • 12.  Re:  PreSaveTrigger - Type and Rootcause

    Posted Jun 01, 2017 02:19 AM

    Thanks my friend, for your patience. =)

     

    I put the code on the detail_in just like you send to me. The alert message on line 4 is this one:

     

     

    I think the function didn't work. Did I miss any thing?



  • 13.  Re:  PreSaveTrigger - Type and Rootcause

    Posted Jun 01, 2017 02:31 AM

    oops, i forgot to get values from input objects. Check updated zCompareRCandType in my prev post.



  • 14.  Re:  PreSaveTrigger - Type and Rootcause

    Posted Jun 01, 2017 05:36 AM

    Hi my friend,

     

    I think the function aren't updating the value when I change it.

    Look this sample attached. This ticket have the wrong informations, I change it, but when I click save, I receive the message for the old values, not for the new ones.

     

    Take a look please. =)



  • 15.  Re:  PreSaveTrigger - Type and Rootcause

    Posted Jun 01, 2017 05:51 AM

    this sounds strage, does it show invalid value for rootcause only or for type too?

     

    Regards,

    cdtj



  • 16.  Re:  PreSaveTrigger - Type and Rootcause

    Posted Jun 01, 2017 06:18 AM

    Hi, 

    yes, it's strange. 

    For both fields. The function are keeping the values that are before I edit th form. 

     

    When I change the values, the function continue keeping the old ones. 



  • 17.  Re:  PreSaveTrigger - Type and Rootcause

    Posted Jun 05, 2017 11:59 AM

    Hi cdtj,

     

    Can you help me with this function?

    Thanks you my friend.



  • 18.  Re:  PreSaveTrigger - Type and Rootcause

    Posted Jun 06, 2017 05:02 PM

    Hi,

    I have updated my previous post, there is some code to collect diag info, hope we can find rootcause of the problem.

    Regards,

    cdtj



  • 19.  Re: PreSaveTrigger - Type and Rootcause

    Posted May 31, 2017 01:40 PM

    1500 rootcauses? Holy grail

     

    Maybe you should try to understand why you have so much rootcauses instead of customizing an itil tool to suit a non-itil env or a non-itil use case?

     

    Probably there is a lack of categories, a misused or unused "affected service concept", and a misused or unused "affected ressource concept".