CA Service Management

 View Only
Expand all | Collapse all

How to Call Javascript Function on Change of Lookup?

  • 1.  How to Call Javascript Function on Change of Lookup?

    Posted Mar 23, 2017 04:37 AM

    Hi Team,

     

    On detail_in page, we can call a javascript function on change of a dropdown field (like Symptom, Resolution Method etc) as follows:

    <PDM_MACRO name=dtlDropdown hdr="Symptom" attr=symptom_code evt="onChange='myJavaScriptFunction();'">

     

    But in case of hierarchical field like request area and lookup field like Assignee, when we call user defined function on change event, they don't work.

     

    How to call a javascript function on change event of hierarchical field and lookup field?

     

    Kindly provide a syntax for that.

     

    Thanks & Regards,

    Balram 



  • 2.  Re: How to Call Javascript Function on Change of Lookup?

    Posted Mar 23, 2017 01:43 PM

    Works for me. Here are test changes I made to the detail_cr.htmpl file:

    function myFunction()
    {
      alert("I've been called.");
    }
    ...
    <PDM_IF "$env.NX_REQUIRE_REQUEST_ASSIGNEE" == "Yes">
    <PDM_MACRO name=dtlLookup hdr="Assignee" attr=assignee evt="onBlur=\\\"detailSyncEditForms(this)\\\" onChange=\\\"myFunction()\\\"" make_required=yes>
    <PDM_ELSE>
    <PDM_MACRO name=dtlLookup hdr="Assignee" attr=assignee evt="onBlur=\\\"detailSyncEditForms(this)\\\" onChange=\\\"myFunction()\\\"">
    </PDM_IF>
    ...
    <PDM_MACRO name=dtlDropdown hdr="Urgency" attr=urgency lookup=no evt="onChange=\\\"myFunction()\\\"">

    Watch out for case sensitivity.


  • 3.  Re: How to Call Javascript Function on Change of Lookup?

    Posted Mar 24, 2017 12:31 AM

    Hi Lindsay,

     

    Thanks for the response!

     

    I applied it on the Affected End User field (Lookup field). Although it is working, but it is being called twice each time I change the value after typing the keys in the text field and picking my value from the autofill options. Apart from this, it is not getting called when I am changing the value using the lookup link option. How to call this function in this case also? Why the function is getting called twice when I am using autofill option? It is called when I click the option in the autofill options, and immediately again after that.

     

    Here is my code for the affected end user field:

     

    <PDM_MACRO name=dtlLookup hdr="Affected End User" attr=customer evt="onBlur='calculateUrgency()' onChange=\\\"myFunction()\\\"">

     

    Regards,

    Balram



  • 4.  Re: How to Call Javascript Function on Change of Lookup?

    Broadcom Employee
    Posted Mar 23, 2017 02:21 PM

    You mean something like this?:

    <PDM_MACRO name=dtlHier hdr="My hdr" attr=z_myatt autofill=no evt="onChange=\\\"my_fun(...')\\\"" factory=my_factory>

    it should work...pay attention to the \\\ here. Thanks _Chi



  • 5.  Re: How to Call Javascript Function on Change of Lookup?

    Posted Mar 24, 2017 12:34 AM

    Hi Chen,

     

    Thanks for your response!

     

    In case I need to call my_fun() for out of box field Incident Area which is like this:

     

    <PDM_MACRO name=dtlHier hdr="Incident Area" attr=category autofill=no evt="onChange=\\\"change_category_func('in',null,'pcat_in')\\\" onBlur='calculateUrgency()'" factory=pcat_in>

     

    It is already calling an out of box function change_category_func using the complex syntax. If I need to add my_func() call in this syntax, what will be the final code for this?

     

    Kindly suggest.

     

    Regards,

    Balram



  • 6.  Re: How to Call Javascript Function on Change of Lookup?

    Posted Mar 24, 2017 12:47 AM

    Hi Chen,

     

    I am able to call my function on Incident area field using the following code:

    <PDM_MACRO name=dtlHier hdr="Incident Area" attr=category autofill=no evt="onChange=\\\"change_category_func('in',null,'pcat_in'); myFunction()\\\" onBlur='calculateUrgency()'" factory=pcat_in>

     

    But, it is causing the same issue as it is giving for lookup field of affected end user that I explained to Lindsay_Estabrooks in my previous comment.

     

    Although it is working, but it is being called twice each time I change the value after typing the keys in the text field and picking my value from the autofill options. Apart from this, it is not getting called when I am changing the value using the link option which opens the pop up to select the incident area. How to call this function in this case also? Why the function is getting called twice when I am using autofill option? It is called when I click the option in the autofill options, and immediately again after that.

     

    Thanks & Regards,

    Balram



  • 7.  Re: How to Call Javascript Function on Change of Lookup?

    Broadcom Employee
    Posted Oct 27, 2017 05:27 PM

    Hey Balram,

     

    Is this still an item that needs to be looked on for?

     

    Thx

    _R



  • 8.  RE: Re: How to Call Javascript Function on Change of Lookup?

    Posted Nov 19, 2019 03:54 AM
    The category field is a very special one. The usual onChange event customization doesn't work, because
    1) autofill is disabled
    2) the OOTB onChange event is defined to launch change_category_func whose principal purpose is to display load_properties.htmpl which is designed to fill the Properties tab if area properties are defined.
    3) that prevents any additional custom  javascript code to run, but I haven't spent the time to find all use cases.

    The only safe way I've found so far to do things after the category has changed is to add custom code to load_properties.htmpl. In that page, $args.category links to the category record in use in the call_request.

    Hope that helps


  • 9.  Re: How to Call Javascript Function on Change of Lookup?

    Posted Nov 29, 2017 08:40 AM

    Hi Balram.Deswal  - do you still need assistance on this one?



  • 10.  Re: How to Call Javascript Function on Change of Lookup?

    Posted Dec 27, 2017 02:27 AM

    Could you please take a look at this thread -

     

    how can i enter value dynamically while lisa is running a test? 

     

    -Regards.



  • 11.  RE: Re: How to Call Javascript Function on Change of Lookup?

    Posted Nov 04, 2019 08:00 AM
    Edited by Granger Gladys Nov 05, 2019 02:12 AM
    I'm fairly new to forms, and have only worked with Update 3.  I too have felt like lookups are not always working like I would think they should be - and I can definitely understand the frustration with something ceasing to work when it had been before visit official website
    .