Personalized Community is here!
Quickly customize your community to find the content you seek.
Have questions on moving to the cloud? Visit the Dynamics 365 Migration Community today! Microsoft’s extensive network of Dynamics AX and Dynamics CRM experts can help.
2022 Release Wave 1 PlanDynamics 365 release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.
2022 release wave 1 plan
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Community | FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Upcoming TechTalks | All TechTalks
I would like to clone a quote by plugin but it fails with "Cannot insert duplicate key row in object 'dbo.QuoteBase' with unique index 'ndx_Unique_Quote'. The duplicate key value is redacted".
I am trying to simply copy the entity to an new one and create that one. I am aware of the problematic with primary key field so i remove the old guid in property id and the attributes list. I am also replacing the values of Money/EntityReference/OptionSetValue-fields with a function i found in antoher thread to prevent conflicts there.
Heres my code - "OriginalQuote.record" is the orginal entity retrieved by:
Entity record = client.Retrieve(
The function i use for replacing sepecial attributes:
public static Entity CloneEntitySandbox(Entity entityToClone)
var newEntity = new Entity(entityToClone.LogicalName);
var systemAttributes = new List<string>();
foreach (var attribute in entityToClone.Attributes
.Where(x => x.Key != entityToClone.LogicalName + "id")
.Where(x => !systemAttributes.Contains(x.Key)))
var m = attribute.Value as Money;
newEntity[attribute.Key] = new Money(m.Value);
var er = attribute.Value as EntityReference;
newEntity[attribute.Key] = new EntityReference(er.LogicalName, er.Id);
var os = attribute.Value as OptionSetValue;
newEntity[attribute.Key] = new OptionSetValue(os.Value);
newEntity[attribute.Key] = attribute.Value;
The cloning logic itself:
Entity newQuote = CloneEntitySandbox(OriginalQuote.record);
//Set the EntityState to null, so that a new cloned record can be created
newQuote.EntityState = null;
//remove the PrimaryId of the record otherwise will show you error
newQuote.Attributes.Remove(newQuote.LogicalName + "id");
newQuote.Id = Guid.NewGuid();
newQuote.Attributes["name"] += " (copy)";
tracingService.Trace("newQuote.name: " + newQuote.Attributes["name"]);
tracingService.Trace("newQuote.Id: " + newQuote.Id.ToString());
What could cause these problems?
To be honest I'm not sure why do you need all that code. The following should be enough:
Entity record = client.Retrieve(
record.Id = Guid.Empty;
//I believe this is the attribute that blocks the create
Thank you for the quick response!
"To be honest I'm not sure why do you need all that code. The following should be enough:"
Pure despair ; -)
I removed the CloneEntitySandbox method and added the suggested removal off the quotenumber.
That seems to fix the problem - the record is cloned successfully!
So my conclusion is that the quotenumber field is an index field also. Where is such an information communicated in the docs? I looked in XRMToolbox's Entity Relation Diagramm and it is just a normal column.
I believe it's just the knowledge I got during years implementing the system. I'm not sure if it's documented anywhere.
If my reply (or replies) answers your question take a minute and verify the answer. You can do it by clicking "Yes" at the top of the reply (or replies) under the label "Does this answer your question?"
Business Applications communities