0
votes

When a user sets the "Scope" on an Opportunity record to "Parent Opportunity", a grid appears that allows the user to create child Opportunity records associated with the parent. I am trying to create a web resource for an OnLoad event that will auto-populate the Opportunity Name, Contact, and Account of the QuickCreate form with the data that is in the Parent Opportunity form. Account and Contact are lookups to separate entities, and Opportunity Name is a text field. Here is what I have so far:

function SetLocalStorage(executionContext)
{

var formContext = executionContext.getFormContext();
var account = formContext.getControl("ParentAccountId").getAttribute().getValue();
var contact = formContext.getControl("ParentContactId").getAttribute().getValue();
var oppname = formContext.getControl("new_name").getAttribute().getValue();

localStorage.setItem("Account", account);
localStorage.setItem("Contact", contact);
localStorage.setItem("OpportunityName", oppname);

}

I am fairly new to JavaScript and am not really sure what to add to the web resource in order for the QuickCreate form to auto-populate. Any help would be greatly appreciated.

Thanks!

1

1 Answers

0
votes

I would propose Codeless solution. Dynamics 365 already provides out of box feature for the same requirement.

For sake of explanation, I have taken Account and Contact Entity.

So from Account If I want to create Contact, few of information shall be autopopulated as shown in Image below.

enter image description here

Now how do I do this. There is 1:N relationship from Account to Contact. So in your case there will be 1:N relationship from Opportunity to Scope. Just like below image

enter image description here

Now when you go inside relationship you will have mapping. What this mapping does it copy data from Source to Target fields. In my case I have few fields been mapped from Account to contact. You can do the same and this will solve your issue.

enter image description here