Hello.
I am trying to create a duplicate record of the Quote table with another id, but it always gives me an error 'The provided key was not found in the dictionary'.
My code is this:
public void CopyQuote(Entity entity, IOrganizationService service)
{
try
{
string newquote = "test";
Entity regnew = new Entity("quote");
foreach (KeyValuePair<String, Object> attribute in entity.Attributes)
{
if (attribute.Key == "quoteid")
{
Guid id = Guid.NewGuid();
regnew ["quoteid"] = id;
}
else if (attribute.Key == "name")
regnew ["name"] = newquote;
else if (attribute.Key != "quotenumber")
regnew ["quotenumber"] = newquote;
else if (attribute.Key != "statecode")
regnew ["statecode"] = 0;
else if (attribute.Key != "statuscode")
regnew ["statuscode"] = 1;
else
{
string attributeName = attribute.Key;
object attributeValue = attribute.Value;
regnew [attributeName] = attributeValue;
}
}
service.Create(regnew);
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
I have tried with a simple:
Entity regnew = new Entity("quote");
Guid id = Guid.NewGuid();
regnew ["quoteid"] = id;
service.Create(regnew);
But it gives me the same error. It has to be something that escapes me, because I have tried the same thing with a custom table and it duplicates it without problems.
May be you can't duplicate on tables that aren't custom?
Greetings and thanks.