Hi Below is the way you can create a multiple copies of any record of any entity.
Let say I have 1 record of contact which I need to make close
// Parent Contact Record
Entity oldcontact = crmservice.Retrieve("contact", ContactId,new ColumnSet(true));
// Child Contact Record
Entity newcontact;
newcontact = oldcontact.Clone(true);
newcontact.Attributes.Remove("contactid"); // This is very important step in cloning as you have to avoid duplicate primary key error.
newcontact.Id = Guid.NewGuid(); // create new GUID for new record
crmservice.Create(newcontact);
And you will get a copy of parentcontact record into childcontact
Enjoy.
Let say I have 1 record of contact which I need to make close
// Parent Contact Record
Entity oldcontact = crmservice.Retrieve("contact", ContactId,new ColumnSet(true));
// Child Contact Record
Entity newcontact;
newcontact = oldcontact.Clone(true);
newcontact.Attributes.Remove("contactid"); // This is very important step in cloning as you have to avoid duplicate primary key error.
newcontact.Id = Guid.NewGuid(); // create new GUID for new record
crmservice.Create(newcontact);
And you will get a copy of parentcontact record into childcontact
Enjoy.
No comments:
Post a Comment