RE: Mapping Fields does not work if the record is not saved
Hi,
As you have already noticed that the out of box mapping will only work when the record is saved. This makes sense cause the parent is not saved hence there is no record to pull the data from in database.
Unfortunately there is no supported way to pass the data from parent to child without saving. I tried some unsupported javascript and it seems to be working fine. You can try and see if it works for you. However it is recommended to not use any unsupported code as it *will* break in future.
You need to register this method on load. You also need to replace the field schema values.
=================
function loadParentDetails() {
try {
// Load Account from Parent to Child record
var parentAccount = window.top.frames[0].Xrm.Page.getAttribute("parentaccountid").getValue();
Xrm.Page.getAttribute("parentcustomerid").setValue(parentAccount);
}
catch (err) {
console.log(err.message);
}
}
=====================
Alternatively you could redesign your implementation pass the form data as parameters to form. With this you need to create a separate ribbon button and call the Xrm.Navigation.openForm function to open the child record and pass the data as form parameters.
docs.microsoft.com/.../set-field-values-using-parameters-passed-form
You can refer these thread on this:
community.dynamics.com/.../how-to-pass-parameters-using-openentityform
community.dynamics.com/.../mapping-parameters-when-opening-a-new-form
Hope this helps.