Notifications
Announcements
No record found.
Hello Experts,
is there a way to copy an Entity in C# without knowing the fields?
I will make a Workflow Step where i can copy or clone every Entity in CRM.
Kind Regards,
Léon
*This post is locked for comments
Hello Léon.
Maybe this can help you:
debajmecrm.com/.../clone-record-dynamics-crm-clone-method
Kind regards,
Karsten
Hello Karsten,
my code is know ready, but if i try to execute them in my CRM than i got this error and i dont know how to fix it..
<Message>Unexpected exception from plug-in (Execute): WorkflowActivityLibrary5.SeminareKopieren: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Xrm.Client, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.</Message>
Leon,
Remove reference on Microsoft.Xrm.Client. This assembly is not available in the sandbox.
But i work with this .dll :D
This is my code and the "Clone" extentsion only exist in Microsoft.Xrm.Client.
// Seminar ermitteln Entity Seminar = service.Retrieve(rref.LogicalName, rref.Id, new ColumnSet(true)); EntityReference Id = Seminar.ToEntityReference(); //Record klonen Entity newSeminar = EntityExtensions.Clone(Seminar, false); Seminar.Id = Guid.Empty; //service.Create(newRecord); tracingService.Trace(Convert.ToString(newSeminar.LogicalName)); QueryExpression query = new QueryExpression("mrd_seminarinhalt"); query.Criteria.AddCondition("mrd_ak_seminarid", ConditionOperator.Equal, Id); // Query ausfürhen EntityCollection retrieveedxpan = service.RetrieveMultiple(query); if (retrieveedxpan.Entities.Count == 0) { // Datensätze wurden nicht gefunden tracingService.Trace("Es wurden keine Seminarinhalte gefunden!"); } else { foreach (var entity in retrieveedxpan.Entities) { //ChildRecord ermitteln Entity ChildSeminar = new Entity("mrd_seminarinhalt"); //ChildRecord klone var newChildSeminar = EntityExtensions.Clone(ChildSeminar, false); newChildSeminar.Id = Guid.Empty; tracingService.Trace(Convert.ToString(newChildSeminar.LogicalName)); //service.Create(newChildRecord); } }
I'm really sorry but you will have to write own extension replacing this "Clone" method with your own code.
If you want your code work to work you will have to follow this.
Hi Leon,
Maybe this will help you out.
community.dynamics.com/.../cloning-a-record-in-dynamics-crm
It has a step by step procedure on creating a clone of a record.
Hope this helps.
Hello,
so now i can copy entitys but that leads to antoher problem.
If i copy my Entity i want to copy the related Entitys to.
But i can't assigne the related Entity to my "Master" Entity.
The code cant find the ID from my "Master" Entity
This is my code:
//Record clone Entity CloneSeminar = Seminar; CloneSeminar.Id = Guid.Empty; CloneSeminar.Attributes.Remove("mrd_seminarid"); CloneSeminar.Attributes.Remove("mrd_ak_seminarbeginn"); CloneSeminar.Attributes.Remove("mrd_ak_seminarende"); CloneSeminar.Attributes.Remove("mrd_ak_seminarnummer"); service.Create(CloneSeminar); tracingService.Trace("Seminar wurde erstellt"); CloneSeminar.ToEntityReference(); Clone.Set(executionContext, CloneSeminar); // Retrive related Entities QueryExpression query = new QueryExpression("mrd_seminarinhalt"); query.Criteria.AddCondition("mrd_ak_seminarid", ConditionOperator.Equal, rref.Id); // Query EntityCollection retrieveedxpan = service.RetrieveMultiple(query); if (retrieveedxpan.Entities.Count == 0) { // Datensätze wurden nicht gefunden tracingService.Trace("Es wurden keine Seminarinhalte gefunden!"); } else { foreach (var entity in retrieveedxpan.Entities) { entity.Attributes.Remove("mrd_seminarinhaltid"); //CloneSeminarinhalt ermitteln Entity CloneSeminarinhalt = entity; CloneSeminarinhalt.Id = Guid.Empty; CloneSeminar.Attributes.Remove("mrd_seminarinhaltid"); CloneSeminar.Attributes.Remove("mrd_ak_seminar"); CloneSeminar.Attributes["mrd_ak_seminar"] = CloneSeminar.Id; //service.Create(CloneSeminarinhalt); tracingService.Trace(Convert.ToString(CloneSeminar.Attributes["mrd_seminarid"])); tracingService.Trace(Convert.ToString(CloneSeminarinhalt.Id)); tracingService.Trace("Seminarinhalt wurde erstellt und zugewießen"); } } }
Hi,
You can retrieve entity metadata using retrieveentityrequest and use this metadata to create entity
Following links may be helpful to you:
msdn.microsoft.com/.../microsoft.xrm.sdk.messages.retrieveentityrequest.aspx
msdn.microsoft.com/.../gg509071.aspx
Hope this helps:)
1. When you create record using service.Create method id of record is not set automatically but it is returned as a result of call. Replace
service.Create(CloneSeminar);
with line
CloneSeminar.Id = service.Create(CloneSeminar);
2. Looks like you're working with collection in your loop but your code modifies parent record instead of child:
CloneSeminar.Attributes.Remove("mrd_seminarinhaltid");
CloneSeminar.Attributes.Remove("mrd_ak_seminar");
CloneSeminar.Attributes["mrd_ak_seminar"] = CloneSeminar.Id;
Should it be CloneSeminarinhalt instead?
3. I assume that mrd_ak_seminar is lookup field and you populate it with Guid value. During the creation it will throw an error so you should replace line
CloneSeminarinhalt.Attributes["mrd_ak_seminar"] = CloneSeminar.Id;
CloneSeminarinhalt.Attributes["mrd_ak_seminar"] = CloneSeminar.ToEntityReference();
Hello Andrew,
thank you :) im so blind...
Now it works fine.
Thank you all for your help!
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2