Just imagine that you need to define the context in which “Quick Create Form” was opened and depending on the context – to do some additional operations. In this short post I provide supported code you can use to define it.
Create JavaScript webresource and add following code inside:
function quickCreateOnLoad(){ //this variable contains entity reference to the parent record var parentRecordReference = Xrm.Utility.getPageContext().input.createFromEntity; //if this variable is null then Quick Create Form was called from the Global Menu //or from some other code without setting the parent record context if (parentRecordReference == null){ return; } //you can use value of parentRecordReference in your code console.log(parentRecordReference.id); console.log(parentRecordReference.entityType); console.log(parentRecordReference.name); }
Add this webresource to the “Quick Create Form” and register quickCreateOnLoad to handle OnLoad event of the form.
Is this code supported with Dynamics 365 v9?
Hello,
This code should work fine for Online and UCI but I’m not fully certain that it’ll work for the on-prem and classic UI.
Andrew
Thanks, this code “Xrm.Utility.getPageContext().input.createFromEntity” doesn’t work if the parent form is in new mode. Is there a way to directly get the context of the parent form from the child quick create?
That is a great question and I have no idea. What information in particular do you want to get from the parent record that was not created yet?
This solution works perfect if u already have a record created (parent form) and invoke QC on top of it.
Similarly, my users are creating new opp record (hasnt saved it yet), entered account info and for contact they tried to create a new contact record which is opening the QC form. Since the parent form – opp hasnt been created yet, i just need the info of the account GUID which i entered in my parent opp form. I tried above command but it returned null. In this unique scenario, how am i suppose to retrieve the account info?
Thanks in advance
Hello,
In the case you described I don’t see any easy way to implement your requirement.
Andrew
Greetings,
Thanks for the post. I have an issue I haven;t been able to solve. There are to subgrids that on an account form that refer to contacts. Both in which you can quick create. When the user does a contact quick create from any of these subgrids, I need to be able to identify what subgrid triggered the contact quick create form. I landed here thinking that I need to get the parent entity of the quick create that was triggered? I tried to get this onload of the quick create form but unsuccessful. I tried many things on getting controls but to no avail have I been able to identify which subgrid triggered it. Any suggestions on this?
Jeffrey,
That’s a tough one. I would say you could try to override “New” button using Ribbon Workbench for the subgrid and pass the subgrid’s name as an additional parameter to the quick create form. I’m not sure if it’s doable or not but that would be the path I would check first.
Andrew
Hello Andrew,
After fetching the parent record reference, is there a way to further access the field values in the parent record?
Hello,
You can use Xrm.WebApi.retrieveRecord in order to receive the record.
Andrew