Hi Codiax,
You have no control of the code that gets executed when you click the New button. It is generated by the application layer. You do have control to modify entity data using Rest Api or actions.
What this means is that after you create a new record (you can do this on the Change event of the Contact Lookup control), you can update the Contact record with the Account Id of the Opportunity record.
You can use CRM Rest Builder (github.com/.../CRMRESTBuilder) to build your Rest Query. You will need to add SDK.REST.js to your solution which is found in the SDK.
Here is sample code to update the Contact Entity with an Account Id (from CRM Rest Builder):
var entity = {};
entity.ParentCustomerId = {
Id: "45678901-5678-5678-5678-0123456789AB",
LogicalName: "account"
};
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/ContactSet(guid'12345678-1234-1234-1234-123456789ABC')", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("X-HTTP-Method", "MERGE");
req.onreadystatechange = function() {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 204 || this.status === 1223) {
//Success - No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));