Hi
I've written the following to update fields on the opportunity with data from a related entity. This should happen on OnChange, but the field are not populated before the form has been saved
Can you see what is wrong?
function retrieveServiceAvailabilityInfo(executionContext) { var city; var postalCode; var province; var serviceArea; //var policeGuard; formContext = executionContext.getFormContext(); var serviceAvailabilityEntity = formContext.getAttribute('cgi_serviceavailability'); var sAEID = 'F0A708D3-9700-EA11-A811-000D3AF3A041'; //serviceAvailabilityEntity.getValue()[0].id; Xrm.WebApi.retrieveRecord('cgi_serviceavailability', sAEID,'?$select=cgi_city,cgi_postalcode,cgi_province,cgi_servicearea').then( function success(result) { city = result.cgi_city; postalCode = result.cgi_postalcode; province = result.cgi_province; serviceArea = result.cgi_servicearea; //policeGuard = result.cgi_policeguard; var data = { 'cgi_city': city,'cgi_postalcode': postalCode,'cgi_province': province,'cgi_servicearea': serviceArea } Xrm.WebApi.updateRecord('opportunity',formContext.data.entity.getId(), data).then(successCallback, errorCallback); formContext.data.entity.save(); }, function (error) { alert('Error'); } ); }