我正在编写一个插件,将合同产品从合同复制到新创建的机会。它似乎可以很好地复制现有产品,但如果有任何写入产品就会出现问题。写入机会产品似乎已正确复制,但当我尝试打开它时,我收到一条消息,指出发生了错误。该插件似乎已成功完成。
任何人有任何想法可能会发生什么?
这是代码:
//Operate on each contract product found
foreach (var contProd in contProdCollection.Entities)
{
//Create the new opp product
Entity newOppProd = new Entity("opportunityproduct");
//Get comm rate from the old connection
ColumnSet contProdCols = new ColumnSet("isproductoverridden", "productid", "uomid", "ispriceoverridden", "quantity", "priceperunit", "extendedamount", "new_costperunit", "new_totalcost");
Guid contProdId = contProd.Id;
Entity contProd2 = service.Retrieve("quotedetail", contProdId, contProdCols);
newOppProd.Attributes["opportunityid"] = newOpp;
//check whether the product is a write in or not
if (contProd2.GetAttributeValue<Boolean>("isproductoverridden") == false)
{
//product is existing
//fill in the details of the new opp product
newOppProd.Attributes["isproductoverridden"] = contProd2.Attributes["isproductoverridden"];
if (contProd2.Contains("productid") == true)
{
newOppProd.Attributes["productid"] = contProd2.Attributes["productid"];
}
if (contProd2.Contains("uomid") == true)
{
newOppProd.Attributes["uomid"] = contProd2.Attributes["uomid"];
}
if (contProd2.Contains("ispriceoverridden") == true)
{
newOppProd.Attributes["ispriceoverridden"] = contProd2.Attributes["ispriceoverridden"];
}
if (contProd2.Contains("quantity") == true)
{
newOppProd.Attributes["quantity"] = contProd2.Attributes["quantity"];
}
if (contProd2.Contains("priceperunit") == true)
{
newOppProd.Attributes["priceperunit"] = contProd2.Attributes["priceperunit"];
}
if (contProd2.Contains("extendedamount") == true)
{
newOppProd.Attributes["extendedamount"] = contProd2.Attributes["extendedamount"];
}
if (contProd2.Contains("new_costperunit") == true)
{
newOppProd.Attributes["new_customerrate"] = contProd2.Attributes["new_costperunit"];
}
if (contProd2.Contains("new_totalcost") == true)
{
newOppProd.Attributes["new_customercost"] = contProd2.Attributes["new_totalcost"];
}
service.Create(newOppProd);
}
else
{
//product is write in
newOppProd.Attributes["isproductoverridden"] = contProd2.Attributes["isproductoverridden"];
if (contProd2.Contains("productdescription") == true)
{
newOppProd.Attributes["productdescription"] = contProd2.Attributes["productdescription"];
}
if (contProd2.Contains("ispriceoverridden") == true)
{
newOppProd.Attributes["ispriceoverridden"] = contProd2.Attributes["ispriceoverridden"];
}
if (contProd2.Contains("quantity") == true)
{
newOppProd.Attributes["quantity"] = contProd2.Attributes["quantity"];
}
if (contProd2.Contains("priceperunit") == true)
{
newOppProd.Attributes["priceperunit"] = contProd2.Attributes["priceperunit"];
}
//if (contProd2.Contains("extendedamount") == true)
//{
// newOppProd.Attributes["extendedamount"] = contProd2.Attributes["extendedamount"];
//}
if (contProd2.Contains("new_costperunit") == true)
{
newOppProd.Attributes["new_customerrate"] = contProd2.Attributes["new_costperunit"];
}
if (contProd2.Contains("new_totalcost") == true)
{
newOppProd.Attributes["new_customercost"] = contProd2.Attributes["new_totalcost"];
}
service.Create(newOppProd);
}
}