CA Service Management

Expand all | Collapse all

%25 Filter Javascript

  • 1.  %25 Filter Javascript

    Posted Feb 27, 2015 11:47 AM

    Hey guys!!!

     

    I need to set a specific contact on a customized atribute every time a category is selected.

     

    If the category is "A" the “executor” will be " ABCD " .

     

    I created a javascript with this functionality, however, I would like to filter only the categories beginning with a specific value, for example " Application % " so that every time this category is selected the executor will be " ABCD " .

     

    Could help me with this code ?

     

    I saw that the 25% is the reference to the % in javascript, but didn't work...

     

    The code:

     

    function zseta_tec_responsavel() {

                        if("$args.category.sym" == "Aplicações Nacionais.%25"){

                        document.main_form.elements["SET.zassignee_exec"].value = "";

                        document.main_form.elements["zassignee_exec_combo_name"].value = "CColares Nehme, Thiago ";

                       }

    }



  • 2.  Re: %25 Filter Javascript

    Posted Feb 27, 2015 01:26 PM

    Could you use the Javascript indexOf function? This function returns the index of the start of the substring if found. If it is not found, it returns a '-1'. So, in your above code it would look like:

     

    function zseta_tec_responsavel() {

                        if("$args.category.sym".indexOf("Aplicações Nacionais.") >= 0){

                        document.main_form.elements["SET.zassignee_exec"].value = "";

                        document.main_form.elements["zassignee_exec_combo_name"].value = "CColares Nehme, Thiago ";

                       }

    }



  • 3.  Re: %25 Filter Javascript

    Broadcom Employee
    Posted Feb 27, 2015 02:41 PM

    I think you would need to use

    indexOf()==0

    to tell if it begins with that string. If you used >=0, it simply says "contains" not "beging with/startwith". For example,

    "My Application.Something".indexOf("Application")>=0

    is true, but

    "My Application.Something".indexOf("Application")==0

    is false.




  • 4.  Re: %25 Filter Javascript

    Posted Feb 27, 2015 02:45 PM

    Good catch. That is true, it would need to be == 0 if it is just the start of the string.



  • 5.  Re: %25 Filter Javascript

    Posted Feb 27, 2015 03:17 PM

    Hey guys!!!!!!!!

     

    Thank you for the help !!!

     

    Before seeing the solution presented by you i create a variable for the argument "$ args.category.sym" and doing a substring then.

     

    The two solutions worked perfectly; however when the ticket is saved the value of the customized attribute is not presented in the form and an error message is displayed.

    erro.jpg

    What am I doing wrong !?



  • 6.  Re: %25 Filter Javascript

    Posted Feb 27, 2015 03:36 PM

    This is the message of google chrome about the error...

     

    "Uncaught TypeError: Cannot set property 'value' of undefined"



  • 7.  Re: %25 Filter Javascript

    Posted Feb 27, 2015 03:41 PM

    What I could see is that the value is placed in the field but is not validated by the form, when I click save it dont load the contact in this new field.

    I tried to replace the contact name in the javascript for the log.agent attribute, but still remains in error.

     



  • 8.  Re: %25 Filter Javascript

    Posted Feb 27, 2015 04:49 PM

    Sorry I did not look at the rest of the code too closely. Have you tried the following:


    document.main_form.elements["SET.zassignee_exec"].value = "<UUID OF CONTACT>";

    //document.main_form.elements["zassignee_exec_combo_name"].value = "CColares Nehme, Thiago "; <-- This line probably doesnt work right. At least "zassignee_exec_combo_name" should be "zassignee_exec.combo_name"

     

    The field will not will not populate instantly, but when you save it it, it should have the new value in it. I am note sure the best way to get it to show while you are editing the ticket, though. I just know that by setting the SET value, it should show after you save the ticket as long as the field is not updated another way before it is saved.



  • 9.  Re: %25 Filter Javascript

    Posted Mar 02, 2015 02:12 PM

    Thanx for the help Benjamin!!!

     

    I tried to modify the code the way you had directed , but still keep getting error message while trying to save the form.

    For some reason the data is not validated when I click " save" , hoped that at least the contact window was presented to the analyst selected the correct value ...

     

    I made some modifications to the code , but the error persists.

     

    Some ways I've tried...

     

    function zseta_tec_responsavel() {

      if ("$args.category.sym".indexOf("Aplicações Nacionais.") == 0){

      document.main_form.elements["SET.zassignee_exec"].value = "E5AEC8D1815CA248B9E2316774BAF20D";

      document.main_form.elements["zassignee_exec_combo_name"].value = "Costa de Queiroz, Marcelo ";

        }

    }

     

    =======

     

    function zseta_tec_responsavel() {

      if ("$args.category.sym".indexOf("Aplicações Nacionais.") == 0){

      document.main_form.elements["SET.zassignee_exec"].value = "$args.zassignee_exec";

      document.main_form.elements["zassignee_exec_combo_name"].value = "Costa de Queiroz, Marcelo ";

        }

    }

     

    =======


    function zseta_tec_responsavel() {

      if ("$args.category.sym".indexOf("Aplicações Nacionais.") == 0){

      document.main_form.elements["SET.zassignee_exec"].value = "Costa de Queiroz, Marcelo ";

      document.main_form.elements["zassignee_exec_combo_name"].value = "Costa de Queiroz, Marcelo ";

        }

    }

     

    I feel I am close to the solution , some small attribute to validate the contact name on the form ...

     

    I thank you again to help!!!!!



  • 10.  Re: %25 Filter Javascript

    Posted Mar 02, 2015 02:32 PM

    For this line:

        document.main_form.elements["zassignee_exec_combo_name"].value = "CColares Nehme, Thiago ";

     

    have you tried changing it to:

        document.main_form.elements["zassignee_exec.combo_name"].value = "CColares Nehme, Thiago ";



    I changed the '_' to a '.' between 'zassignee_exec' and 'combo_name'. Although this line is not necessary, because you are setting the value in the line prior. Try commenting it out and see if you still get the error.



  • 11.  Re: %25 Filter Javascript

    Posted Mar 02, 2015 03:35 PM
      |   view attached

    Hi Benjamin!!

     

    When a change de line:

        document.main_form.elements["zassignee_exec_combo_name"].value = "CColares Nehme, Thiago ";


    To this:

        document.main_form.elements["zassignee_exec.combo_name"].value = "CColares Nehme, Thiago ";


    The value in the custom field is not loaded.

    What happens now is that when change the "SET" argument by "KEY" ond the line "document.main_form.elements["KEY.zassignee_exec"].value = "C917915155AFE64EB13224571126A659"; the form load the "assignee_exec" name in the field, still does a search in the contact form and the bears ... however, when I save the form he disappears from the field and gives error message: "Unable to set property 'value' of undefined or null reference".

     

    For some reason the value is loaded on the form, but is not possible to save him...