Reputation: 935
Problem I am trying to get my accounts to update the composite address with the new address. Al the fields in the customer address show the new values but the composite address shows the old address.
Desired Result: Composite field updates to the new address upon changing the address fields
Actual Result: Composite field shows the old address
Things I've Tried:
Current Code:
Entity theAccount = proxy.Retrieve("account", Guid.Parse("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"), new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
Guid address1_id = theAccount.Attributes.ContainsKey("address1_addressid") ? (Guid)theAccount.Attributes["address1_addressid"] : Guid.Empty;
Entity theAddress = new Entity()
{
LogicalName = "customeraddress",
Id = address1_id
};
theAddress.Attributes["line1"] = null;
theAddress.Attributes["line2"] = null;
theAddress.Attributes["line3"] = null;
theAddress.Attributes["city"] = null;
theAddress.Attributes["stateorprovince"] = null;
theAddress.Attributes["country"] = null;
theAddress.Attributes["county"] = null;
theAddress.Attributes["postofficebox"] = null;
theAddress.Attributes["postalcode"] = null;
theAddress.Attributes["composite"] = null;
proxy.Update(theAddress);
theAddress.Attributes["line1"] = "1 New Street";
theAddress.Attributes["line2"] = null;
theAddress.Attributes["line3"] = null;
theAddress.Attributes["city"] = "New City";
theAddress.Attributes["stateorprovince"] = "New State";
theAddress.Attributes["country"] = "New Country";
theAddress.Attributes["county"] = null;
theAddress.Attributes["postofficebox"] = null;
theAddress.Attributes["postalcode"] = "1234";
proxy.Update(theAddress);
Question How do I successfully change the address composite field in Microsoft Dynamic CRM upon updating the address fields
Upvotes: 0
Views: 1539
Reputation: 23300
You should update the address fields of the Account record, not the CustomerAddress.
i.e.
Entity theAccount = new Entity("account", "XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXX");
theAccount["address1_line1"] = null;
theAccount["address1_line2"] = null;
theAccount["address1_line3"] = null;
theAccount["address1_city"] = null;
theAccount["address1_stateorprovince"] = null;
theAccount["address1_country"] = null;
theAccount["address1_county"] = null;
theAccount["address1_postofficebox"] = null;
theAccount["address1_postalcode"] = null;
theAccount["address1_composite"] = null;
proxy.Update(theAccount);
theAccount["address1_line1"] = "1 New Street";
theAccount["address1_line2"] = null;
theAccount["address1_line3"] = null;
theAccount["address1_city"] = "New City";
theAccount["address1_stateorprovince"] = "New State";
theAccount["address1_country"] = "New Country";
theAccount["address1_county"] = null;
theAccount["address1_postofficebox"] = null;
theAccount["address1_postalcode"] = "1234";
proxy.Update(theAccount);
If this you're doing is a real-time operation of some kind taking place while the form is open, you also might need to invoke Xrm.Page.data.refresh(false)
for the new data to show up.
Upvotes: 3