You can do a plugin that retrieves the record, and within each record, retrieve all Entity Collections for the subgrids/child entities:
// Main Code Base
Entity parent = RetrieveParent(parentId);
if (parent != null)
{
Guid newParentId = CreateParent(parent);
EntityCollection children1 = RetrieveChildren(parent.Id);
if (children1.Entities.Count > 0)
{
foreach (Entity child in children1.Entities)
{
Guid newChild1Id = CreateChild(child, newParentId);
}
}
}
private Guid CreateParent(Entity parent)
{
Entity newParent = new Entity(bgx_Parent.EntityLogicalName);
foreach (KeyValuePair<String, Object> attribute in project.Attributes)
{
string attributeName = attribute.Key;
object attributeValue = attribute.Value;
switch (attributeName.ToLower())
{
case "bgx_parentid":
break;
default:
newParent[attributeName] = attributeValue;
break;
}
}
try
{
Guid parentId = service.Create(newParent);
return parentId;
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in the CreateParent function of the plug-in.", ex);
}
}
private Guid CreateChild(Entity child, Guid parentId)
{
Entity newChild = new Entity("bgx_Child1");
foreach (KeyValuePair<String, Object> attribute in child.Attributes)
{
string attributeName = attribute.Key;
object attributeValue = attribute.Value;
switch (attributeName.ToLower())
{
case "bgx_parentid":
newChild[attributeName] = new EntityReference("bgx_parent", parentId);
break;
case "bgx_childid":
break;
default:
newChild[attributeName] = attributeValue;
break;
}
}
try
{
Guid childId = service.Create(newChild);
return childId;
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in the CreateChildfunction of the plug-in.", ex);
}
}
You can probably create a generic class for the Create Child that will apply to all child entities.
Good luck