Search code examples
javascriptdynamics-crmmicrosoft-dynamicsdynamics-365

Dynamics crm 365 quick create form get parent entity data


When I click on the "New" link in a form's lookup field, the quick create form opens. I need to get values of the parent form to prefill some fields of the quick create form. This can't be done with mappings (as seen in some posts in this site), since it must only work in the quick create form. How can I do this in javascript? There is no other way except using localStorage?

EDIT:

window.parent.Xrm.Page.getAttribute(attribute name).getValue()

does not work


Solution

  • You have two choices, to achieve this in js.

    1. Either in main form scripting you can assign in a global variable and access it in Quick create form. Depends on the version, you may have to manage formContext instead of Xrm.Page. Read more

       var setValsForQuickCreate = function(){
         window.top.attributename = Xrm.Page.getAttribute("new_attributename").getValue();
       }
      
       var setValFromMainForm = function(){
         Xrm.Page.getAttribute("new_attributename").setValue(window.top.attributename);
       }
      
    2. Otherwise, you can query using the web api on form load, filter it based on parent lookup value mapped and fill the fields. You can create a separate library/method for registering in QC form only or check only if it is Quick create form and execute it.