none
Lookup field onchange event not firing in Dynamics CRM 2013

    Question

  • Hi,

    I have lookup field and combobox (optionset) on my form. Lookup field is cleared, if i choose one of values in combobox (I have handler on onchange event). If I put in the lookup field same value as before, the onchange event is not fired. If I put other value, everything is OK.

    Lookup is cleared with this code:

    Xrm.Page.getAttribute("lookupId").setValue(null);

    Any ideas, why onchange event is not fired, when I put same value in the lookup field after deleting it?

    Thanks.

    Thursday, March 06, 2014 10:01 AM

All replies

  • Hi dr00ster,

    Probably there's something to do with the condition you're checking before you clear the lookup? Can you post your code?


    Admin QuikView Solution for CRM 2013

    Thursday, March 06, 2014 10:21 AM
  • Hi Dynamoltion,

    Thanks for quick reply.

    Handler for OptionSet.OnChange:

    function RelationshipTypeOnChange(executionContext) {
       var relationshipType = executionContext.getEventSource().controls.get("sir_relationshiptype").getAttribute().getValue();
       SetFormAccordingRelationshipType(relationshipType);
    }

    Function, which among other things, deletes value from lookup field:

    function SetFormAccordingRelationshipType(relationshipType) {
       if (relationshipType == someValue) {
          Xrm.Page.getAttribute("lookupId").setValue(null);
       }
    }
    I checked the code with debugger in Chrome and it reached line which is used to delete value from lookupfield. So the conditions are met alright (or it look like so).

    Thursday, March 06, 2014 10:36 AM
  • Hi dr00ster,

    I would like to know if your lookup a required field on the form?

    I have seen issues in CRM 2013 with the onchange events not firing for the fields set as required (*) on the form.

    Thanks,

    Swaroop

    Thursday, March 06, 2014 8:10 PM
  • You need to fire the onchange event manually if you are setting the field value for a lookup. Happened to me with CRM 2013.

    Xrm.Page.getAttribute("lookupId").fireOnchange();

    • Proposed as answer by Ahmad Pirani Thursday, March 06, 2014 8:29 PM
    Thursday, March 06, 2014 8:29 PM
  • Hi Swaroop_d,

    lookup, which I am trying to clear and populate with same value, is required. But even if I set requiredlevel to none, the onchange event is not fired.

    Friday, March 07, 2014 8:02 AM
  • Hi Ahmad,

    but I can't fire event manually, because the value is set from the form, not from the js code.

    Friday, March 07, 2014 8:04 AM