Wednesday, 16 August 2017

'Cannot specify child attributes in the columnset for Retrieve' when Merging two Accounts in CRM

Hi,

Today, I was writing C# code for merging two accounts in CRM. For sometime, it was working fine and suddenly it started giving the below error.

Not sure, what happened. Just went back and checked the differences between then and now and understood that I have added couple of fields to the UpdateContent entity object and those are causing the issue.

After some search came to know it was happening because of lookup fields. Whenever, we added lookups field we have to make sure that the entityreference object should not contain value for Name property and we have to explicitly add name attribute to the UpdateContent object as below.

// Add EntityLogicalName + 'Name' property to UpdateContent object.
// updateContent.Attributes.Add("transactioncurrencyame", erfTransactionCurrencyId.Name);
updateContent.Attributes.Add(erfTransactionCurrencyMain.LogicalName + "name", erfTransactionCurrencyId.Name);
// Set the Name Property of the Look up object (Entity Reference) to Null.
erfTransactionCurrencyMain.Name = null;
// Add Lookup object (Entity Reference after setting Name value to Null) to the UpdateContent Object.
updateContent.Attributes.Add("transactioncurrencyid", erfTransactionCurrencyMain);


Hope this helps.

--
Happy CRM'ing
Gopinath

No comments:

Post a Comment