locked
CRM 2011 - quotedetail - dictionary error RRS feed

  • Question

  • I am trying to add a new quotedetail record:

    Guid productid = ((EntityReference)equipment["new_product"]).Id;
    
    EntityReference product = new EntityReference("product", productid);
    
    EntityReference quote = new EntityReference("quote", new Guid("4B21FCDB-996E-E011-8E61-1CC1DE6DEBD9"));
            
    EntityReference uom = new EntityReference("uom", new Guid("FE5BAB02-FD6B-E011-878C-0026558302BB"));
    
    Entity quotedetail = new Entity("quotedetail");
    
    Decimal quantity = 1m;
    
    quotedetail["productid"] = product;
    quotedetail["quantity"] = quantity;
    quotedetail["quoteid"] = quote;
    quotedetail["uomid"] = uom;
    
    service.Create(quotedetail);
    

    I get a "The given key was not present in the dictionary" error.

    I cannot work out which parameter is incorrect?


    ePartners CRM
    Monday, April 25, 2011 11:57 AM

Answers

All replies

  • You first need to add the attributes to the entity before you can assign them.
    Like

    quotedetail.attributes.add("productid", new EntetyReference("product", new Guid(....

    • Proposed as answer by Jan AS Monday, April 25, 2011 3:31 PM
    Monday, April 25, 2011 12:08 PM
  • Like this:

    Guid productid = ((EntityReference)equipment["new_product"]).Id;
    
    EntityReference product = new EntityReference("product", productid);
            
    EntityReference quote = new EntityReference("quote", new Guid("4B21FCDB-996E-E011-8E61-1CC1DE6DEBD9"));
            
    EntityReference uom = new EntityReference("uom", new Guid("FE5BAB02-FD6B-E011-878C-0026558302BB"));
    
    Entity quotedetail = new Entity("quotedetail");
    
    Decimal quantity = 1m;
    
    quotedetail.Attributes.Add("productid", product);
    quotedetail.Attributes.Add("quantity", quantity);
    quotedetail.Attributes.Add("quoteid", quote);
    quotedetail.Attributes.Add("uomid", uom);
    
    service.Create(quotedetail);
    

    I still get the same error


    ePartners CRM
    Monday, April 25, 2011 12:18 PM
  • Does your starting entity realy contain "new_product" (check with .contains) and is it an entityreference or just an id?

    Your entity definition may have the attribute "new_product" but that does not meain it is available in your plugin.

    Monday, April 25, 2011 12:25 PM
  • Does your starting entity realy contain "new_product" (check with .contains) and is it an entityreference or just an id?

    Your entity definition may have the attribute "new_product" but that does not meain it is available in your plugin.

    throw new Exception(equipment.Contains("new_product").ToString()); (returns True)

    It is a lookup back to the product entity


    ePartners CRM
    Monday, April 25, 2011 12:38 PM
  • I get the same problem if I hard code the product:

    EntityReference product = new EntityReference("product", new Guid("07E293B3-976E-E011-8E61-1CC1DE6DEBD9"));
    EntityReference quote = new EntityReference("quote", new Guid("4B21FCDB-996E-E011-8E61-1CC1DE6DEBD9"));
    EntityReference uom = new EntityReference("uom", new Guid("FE5BAB02-FD6B-E011-878C-0026558302BB"));
            
    Entity quotedetail = new Entity("quotedetail");
            
    Decimal quantity = 1m;
            
    quotedetail.Attributes.Add("productid", product);
    quotedetail.Attributes.Add("quantity", quantity);
    quotedetail.Attributes.Add("quoteid", quote);        
    quotedetail.Attributes.Add("uomid", uom);
    
    service.Create(quotedetail);
    


    ePartners CRM
    Monday, April 25, 2011 1:00 PM
  • I also do not see the error. I suggest you mark out every line and un-mark them one by one to find the line with the error.
    Monday, April 25, 2011 1:09 PM
  • It was another plugin that caused the error!!!
    ePartners CRM
    • Marked as answer by ePartners UK Monday, April 25, 2011 1:51 PM
    Monday, April 25, 2011 1:51 PM