Enable smarter selling with embedded AI
Focus on the right customers, build trusted relationships, and take swift action with a solution that unifies relationship data and provides contextual AI-driven insights.
Dynamics 365 2019 release wave 2 plan Discover the latest updates to Dynamics 365.Release Plan | Weekly Deployment Notes
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants.Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements.
ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Talent TechTalks
Hello Everyone,I have a requirement that I have to clone the record of the custom entity and all it's child records which are related.
I'm able to clone the record but unable to understand how to clone it's child record and link them.
Kindly suggest me the solution. It would be really appreciated if someone provide me the code to achieve the same.
thanks in advance..
For cloning records, you'll need to actually create child records manually (or rather clone them as well) in your C#/CustomWorkflowAssembly code. Out Of The Box, there is to feature to clone the child records too.
Else, you can also evaluate products like Click2Clone by Inogic - https://www.inogic.com/blog/2016/06/click2clone-clone-your-dynamics-crm-records-in-one-click/. It's a subscription based service.
Hope this helps.
Thanks for the reference Priyesh. It might be worth while to have a look at the packaged solution. The solution is available for trial from AppSource
In your code, you need to create the clone of child records as well and then link.
Copying the complete code here won't be practical but you can try the following steps.
Assuming you are using a plugin or custom workflow.
1. Clone the parent record.
2. Fetch the child records using RetrievMultiple method.
3. Inside the for each loop assign or get the record to an object of type entity.
4. Set the record GUID to NULL.
5. Set Look reference to the newly cloned parent record.
6. create the child using service.create.
Hope this helps
If this helped you, please mask as verified.
Please refer below code to create clone records:
Entity Patient = (Entity)context.InputParameters["Target"];
Entity Contact = (Entity)context.PreEntityImages["Image"];
foreach (KeyValuePair<String, Object> attribute in Contact.Attributes)
string attributeName = attribute.Key;
object attributeValue = attribute.Value;
Clone_Contact[attributeName] = new EntityReference("systemuser", context.UserId);
Clone_Contact[attributeName] = attributeValue;
Guid ContactId = service.Create(Clone_Contact);
Once you done with create cloned record set new GUID as entity reference to child records
Business Applications communities