Introduction:
In Dynamics 365 CRM, for certain requirements we need to update associations in the related tables i.e., update lookup values. As an example, for a selected contact record account lookup will be updated.
Step 1:
Login to the required environment and select required solution [Contact Customizations Solution in this case] as shown in the below figure.

Step 2:
After Step 1, select contact web resource in solution and click on Edit as shown in the below figure.

Step 3:
After Step 2, we must aprepare data for the account lookup in contact record with the below code
var data =
{
“parentcustomerid_account@odata.bind”: “/accounts(c57ae37c-6cc8-ec11-a7b5-6045bd00d54a)”
}
As shown in the below figure

Step 4:
After Step 3, prepare request to update record in the related table contact by passing data to updateRecord method of Xrm.WebApi after passing other arguments “contact” and guid of contact like below code
Xrm.WebApi.updateRecord(“contact”, contactGUID, data).then(
function success(result) {
console.log(“Contact updated with Account”);
// perform operations on record update
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
As shown in the below figure

Step 5:
After Step 4, final code looks like below
if (typeof (ContosoVaccination) == “undefined”)
{
var ContosoVaccination = {__namespace: true};
}
if (typeof (ContosoVaccination.Scripts) == “undefined”)
{
ContosoVaccination.Scripts = {__namespace: true};
}
ContosoVaccination.Scripts.ContactForm =
{
handleOnLoad: function (executionContext)
{
console.log(‘on load – contact form’);
updateContact(executionContext);
},
__namespace: true
}
function updateContact(executionContext)
{
let formContext = executionContext.getFormContext();
if (formContext !== null && formContext != ‘undefined’)
{
let contactGUID=Xrm.Page.data.entity.getId().replace(“{“,””).replace(“}”,””);
// define the data to update a record
var data =
{
“parentcustomerid_account@odata.bind”: “/accounts(c57ae37c-6cc8-ec11-a7b5-6045bd00d54a)”
}
// update the record
Xrm.WebApi.updateRecord(“contact”, contactGUID, data).then(
function success(result) {
console.log(“Contact updated with Account”);
// perform operations on record update
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
}
}
As shown in the below figure

Step 6:
After Step 5, save Webresource and publish it and register this Webresource in form load event of contact form and publish all the customisations and open a contact record which don’t have any account , once contact records open one can observe account lookup will be filled with the given sample account guid as shown in the below figure.

Note:
- Make sure to publish all customizations and upload JavaScript (js) file.
- To get entity definitions, browse your crm org followed by Entity definition
- Make sure to provide exact logical name of account lookup in contact record by looking at navigation property of type mscrm.account in contact table.
- Microsoft documentation can be found here
Conclusion: In this way, one can easily perform update associations on the related tables using XRM Web API updateRecord method.
Discover more from Common Man Tips for Power Platform, Dynamics CRM,Azure
Subscribe to get the latest posts sent to your email.

Pingback: Back To Basics :Curated List of Articles in a Single Page – Common Man Tips for Power Platform, Dynamics CRM,Azure
Pingback: Rewind May 2022 – Common Man Tips for Power Platform, Dynamics CRM,Azure
Pingback: Rewind May 2022 - Microsoft Dynamics CRM Community
I have 2 table “Chi nhánh” and “Bán hàng’.
In table “Bán hàng” , i have a column “Chi nhánh”(cr44a_chinhanhlk) with type looup to table “Chi nhánh”.
I want update value of column “Chi nhánh” .
Table “Chi nhánh”
https://dev-wecare.crm5.dynamics.com/api/data/v9.0/cr44a_chinhanhs(A88EE952-DEDB-EC11-BB3C-00224815BAA5)
{“@odata.context”:”https://dev-wecare.crm5.dynamics.com/api/data/v9.0/$metadata#cr44a_chinhanhs/$entity”,”@odata.etag”:”W/\”7138715\””,”cr44a_name”:”Wecare S\u00e0i G\u00f2n”,”_owningbusinessunit_value”:”f792e2ea-bd51-ed11-9562-002248570312″,”cr44a_iachi”:”S\u00e0i G\u00f2n”,”statuscode”:1,”_createdby_value”:”8a41ddf0-bd51-ed11-9562-002248570312″,”_ownerid_value”:”8a41ddf0-bd51-ed11-9562-002248570312″,”modifiedon”:”2022-11-19T13:50:44Z”,”_owninguser_value”:”8a41ddf0-bd51-ed11-9562-002248570312″,”_modifiedby_value”:”8a41ddf0-bd51-ed11-9562-002248570312″,”versionnumber”:7138715,”cr44a_chinhanhid”:”a88ee952-dedb-ec11-bb3c-00224815baa5″,”createdon”:”2022-11-07T01:18:10Z”,”statecode”:0,”_owningteam_value”:null,”utcconversiontimezonecode”:null,”importsequencenumber”:null,”timezoneruleversionnumber”:null,”overriddencreatedon”:null,”_modifiedonbehalfby_value”:null,”_createdonbehalfby_value”:null}.
Table “Bán hàng” :
https://dev-wecare.crm5.dynamics.com/api/data/v9.0/cr44a_banhang2s(590b5faf-ed96-ed11-aad1-002248593b27)
{“@odata.context”:”https://dev-wecare.crm5.dynamics.com/api/data/v9.0/$metadata#cr44a_banhang2s/$entity”,”@odata.etag”:”W/\”275497706\””,”cr44a_name”:”BHBD-2301423″,”cr44a_sophieuxuat”:”XKBD-2301423″,”cr44a_nam”:”2023″,”cr44a_trangthailaphoaon”:799880001,”cr44a_tennhanvien”:”V\u00f5 Tr\u1ecdng L\u1ec5″,”cr44a_ngaychungtu”:”2023-01-11T00:00:00Z”,”cr44a_kemphieuxuat”:false,”cr44a_sotienconno”:290000.0000000000,”cr44a_diengiai”:”aaa”,”modifiedon”:”2023-04-01T07:40:18Z”,”_owninguser_value”:”a14bd786-1c54-ed11-9562-000d3ac7ccec”,”cr1bb_maphieuxuattrans”:”PXK-112786″,”cr1bb_tongtienchuathue”:290000.0000000000,”statecode”:0,”cr44a_chiphihoplykhonghoply”:false,”cr1bb_tongtienchuathue_state”:1,”cr44a_iachi”:”\u0110\u1ecbnh Phong, An \u0110\u1ecbnh, Tuy An”,”cr44a_tenphaply”:”aa”,”_cr44a_nhanvienbanhang_value”:”fa16a1e7-8e61-ed11-9562-000d3a856e52″,”cr44a_banhang2id”:”590b5faf-ed96-ed11-aad1-002248593b27″,”cr44a_loaichungtu”:”B\u00e1n h\u00e0ng trong n\u01b0\u1edbc ch\u01b0a thu ti\u1ec1n”,”_ownerid_value”:”a14bd786-1c54-ed11-9562-000d3ac7ccec”,”cr44a_tongtienthanhtoan_state”:1,”cr44a_bhauto”:”BH10000161″,”_cr44a_chinhanhlk_value”:”d715b248-dedb-ec11-bb3c-00224815baa5″,”cr1bb_tongthue_state”:1,”_createdby_value”:”a14bd786-1c54-ed11-9562-000d3ac7ccec”,”cr44a_soathu”:0.00,”cr1bb_tongthue”:0.0000000000,”timezoneruleversionnumber”:26,”cr44a_ghiso”:true,”statuscode”:1,”createdon”:”2023-01-18T05:05:19Z”,”versionnumber”:275497706,”cr44a_thutien”:false,”cr44a_ngayhachtoan”:”2023-01-11T00:00:00Z”,”cr44a_khachhangtext”:”C\u00d4NG TY C\u1ed4 PH\u1ea6N PH\u01af\u1edaC H\u01afNG”,”cr1bb_tongtienchuathue_date”:”2023-04-03T06:51:46Z”,”cr1bb_makhnew”:”KH-4896″,”cr44a_chinhanhtext”:”Wecare B\u00ecnh \u0110\u1ecbnh”,”cr44a_tongtienthanhtoan”:290000.0000000000,”cr44a_makhachhangcalculate”:”KH-4896″,”_cr44a_khachhanglk_value”:”dd599ac1-1db7-ed11-b596-000d3a08d940″,”cr44a_thang”:”1″,”cr44a_makhachhang”:”KH-4411″,”cr44a_tongtienthanhtoan_date”:”2023-04-03T06:51:46Z”,”_cr44a_loaigiaodich_value”:”286d7fd0-e495-ec11-b400-0022481773a4″,”_modifiedby_value”:”a14bd786-1c54-ed11-9562-000d3ac7ccec”,”cr44a_ghisocal”:”Ghi s\u1ed5″,”cr44a_kemhoaon”:false,”cr44a_kemhoaon_choice”:799880000,”cr44a_sctnumber”:423,”cr44a_loaigiaodichcalculate”:”1 – B\u00e1n h\u00e0ng h\u00f3a trong n\u01b0\u1edbc”,”cr1bb_tongthue_date”:”2023-04-03T06:51:46Z”,”cr44a_tenkhachhang”:”C\u00d4NG TY C\u1ed4 PH\u1ea6N PH\u01af\u1edaC H\u01afNG”,”cr44a_masothue”:”0″,”cr44a_chiphihoplykhonghoplytext”:”Chi ph\u00ed kh\u00f4ng h\u1ee3p l\u00fd”,”_owningbusinessunit_value”:”f792e2ea-bd51-ed11-9562-002248570312″,”cr44a_hinhthucthanhtoan”:799880000,”cr44a_manhanvien”:”NV099″,”cr44a_kyhieuhoaon”:null,”cr44a_tentk”:null,”cr44a_nguoinop”:null,”cr44a_ttthanhtoan”:null,”_cr44a_oituongnoco_value”:null,”cr44a_ttxuathang”:null,”cr44a_hanthanhtoan”:null,”_cr44a_nopvaotk_value”:null,”cr44a_khoaso”:null,”cr44a_ngaykhoaso”:null,”_modifiedonbehalfby_value”:null,”importsequencenumber”:null,”utcconversiontimezonecode”:null,”_createdonbehalfby_value”:null,”cr44a_lidonop”:null,”cr44a_ttlaphoaon”:null,”cr44a_ngayhoaon”:null,”_owningteam_value”:null,”cr44a_thamchieu”:null,”cr44a_mausohoaon”:null,”overriddencreatedon”:null,”cr44a_soathutemp”:null,”cr44a_nguoilienhe”:null,”cr1bb_statusquery”:null,”cr44a_sohoaon”:null,”cr44a_songayuocno”:null,”cr44a_ttdulieu”:null,”cr44a_khachhang”:null}
.
Code of me .
Xrm.WebApi.updateRecord(“cr44a_banhang2”, merge.entities[i][“cr1bb_idtablelienket”], {
“cr44a_chinhanhlk@odata.bind”: “/cr44a_chinhanhs(A88EE952-DEDB-EC11-BB3C-00224815BAA5)”
}).then(
function success() {
console.log(“Update bán hàng thành công”);
// perform operations on record update
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
Error code :
[storage] Error Messages:
1: Error identified in Payload provided by the user for Entity :”, For more information on this error please follow this help link https://go.microsoft.com/fwlink/?linkid=2195293 —-> InnerException : Microsoft.OData.ODataException: An undeclared property ‘cr44a_chinhanhlk’ which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.
LikeLike
Based on the error , property was not found in the payload. So, please verify property
LikeLike