Hi
I can't figure out why I am get this error message System.InvalidCastException: Specified cast is not valid.
I am doing a loop to make copies of detail records.
I am creating a reference to add to a lookup field.
Any ideal what is causing this error message?
//Instead of iterating through all the child records and creating one by one we can also use ExecuteMultiple method foreach (Entity retrieve in service.RetrieveMultiple(query).Entities) { //Remove the primary key of the retrieved associated record retrieve.Attributes.Remove("new_selectortemplatequestionid"); retrieve.Attributes.Remove("new_selectortemplateid"); //Set the primary key value to Guid.NewGuid() retrieve.Id = Guid.NewGuid(); EntityReference newselectorTemplateLookup = new EntityReference("new_selectortemplate", selectortemplateId); retrieve.Attributes.Add("new_selectortemplateid", newselectorTemplateLookup); service.Create(retrieve); }
*This post is locked for comments