Getting Following exception while trying to create a clone.
Edit EntityState must be set to null, Created (for Create message) or Changed (for Update message)
Following is the code snippet, please suggest I am missing here ?
public static Guid getParentSurveyClone(IOrganizationService service, acn_myEntity parentEntity) {
try
{
//The bool parameter passed to Clone method is set to true by default.
var childEntity = parentEntity.Clone(true);
childEntity.SetAttributeValue("name", "Child-" + parentEntity.name + "-" + DateTime.Now.ToString());
//Remove all the attributes of type primaryid as all the cloned records will have their own primaryid
childEntity.Attributes.Remove(childEntity.LogicalName + "id");
//create the cloned record
childEntity.EntityState = EntityState.Changed;
var childSurveyId = service.Create(childEntity);
}
catch (SaveChangesException ex)
{
throw ex;
}
}
*This post is locked for comments
I have the same question (0)