locked
Javascript: Web Resource loses lookup value when New button is pressed RRS feed

  • Question

  • I have a web resource which is essentially an HTML page with a drop down list box on it.

    This is displayed in a CRM form and looks very much like a native control.

    When the CRM form is first loaded (always from a parent record) the Web Resource takes the ID value from a hidden Lookup (the parent):

    var parentid = window.parent.Xrm.Page.getAttribute('new_myentitylookupid').getValue()[0].id;

    It uses this to make decisions about what to display in the drop down.

    Unfortunately, if a user choses to save and then clicks on the "New" button direct from the form this line fails to get an ID.

    If the user Saves and Closes and then re-opens the form, all is well.

    By the looks of it the related Lookup field is not populated when the New button is pressed.  I should clarify that this form gets the ID the first time because we are adding a record to a parent entity "new_myentitylookup". I am surprised that this automation stops as soon as "New" button is used in this context.

    Any ideas on what I can do here?

    Monday, January 20, 2014 5:28 PM

All replies

  • This is by design - the mappings between parent and child records only work on the first child record created from the parent. As you've seen, subsequent records created to not inherit the mappings unless you g back to the parent form and start the process over. 

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Monday, January 20, 2014 5:44 PM
    Moderator
  • Thanks for the reply.

    Wondered if anyone has a solution for this situation?

    I would like to make it easy for users to add multiple records.

    The other end of the solution spectrum is to remove the "New" button I guess.

    Monday, January 20, 2014 6:05 PM