
Hi Shubham,
The OOB relationship between Account and Contact is 1:N, so it should that one Account lookup field in the Contact form.
As mentioned above, you want to update fields of contact entity in the Account form, Right?
The account is parent record and contact is child record, one parent record may have many child records.
So what you need is that update child records when parent record is triggered.
1.Reterieve Contacts based on current Account id.
2.Update Contact fields based on contact id that from step1.
3.Replacing the sample id in the screenshot with a dynamic ID in the JS code.
function updateContact() {
var id = Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');//get current account id
Xrm.WebApi.online.retrieveMultipleRecords("contact", "?$select=contactid,telephone1&$filter=_accountid_value eq " id "").then(
function success(results) {
for (var i = 0; i < results.entities.length; i ) {
var contactid = results.entities[i]["contactid"];
var telephone1 = results.entities[i]["telephone1"];
//update child contacts fields
var entity = {};
entity.telephone1 = "test phone update";//use value you need to update fields.
Xrm.WebApi.online.updateRecord("contact", "" contactid "", entity).then(
function success(result) {
var updatedEntityId = result.id;
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
4.Add the js code to the contact form.
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.