hi,
I am trying to create opportunity product programmatically
I have defined dynamic entity becuase we are using custom fields
I am using targetcreatedynamic entity
I have the parent opportunity guid and i use it when creating opp product
However I get the following error
0x80040216 An unexpected error occurred. Platform
I am using the saop exception but this all what i got
is there other way to create opportunity product
below is my code
DynamicEntity dy =
new
DynamicEntity();
dy.Name =
EntityName.opportunityproduct.ToString();
//unit
//dy.Properties.Add(getLookup("Primary Unit", crmservice, "name", EntityName.uom.ToString(), "uomid"));
LookupProperty punit =
new
LookupProperty();
punit.Value =
new
Lookup();
punit.Name =
"uomid";
punit.Value.type =
"uom";
punit.Value.Value =
new
Guid("C326032A-F354-4554-8D68-AB7EF93A4A97");
dy.Properties.Add(punit);
//product
LookupProperty lProduct =
new
LookupProperty();
lProduct.Value =
new
Lookup();
lProduct.Name =
"productid";
lProduct.Value.Value =
new
Guid("08E33D6E-C174-DF11-9B91-000C2936F852");
lProduct.Value.type =
EntityName.product.ToString();
dy.Properties.Add(lProduct);
//opp
LookupProperty opp =
new
LookupProperty();
opp.Name =
"opportunityid";
opp.Value =
new
Lookup();
opp.Value.Value =
new
Guid("9549B10C-1973-DF11-9B91-000C2936F852")
;
opp.Value.type =
EntityName.opportunity.ToString();
//getLookup(oppid, crmservice, "custom_sfoldkey", EntityName.opportunity.ToString(), "opportunityid");
dy.Properties.Add(opp);
//number quantity
CrmNumberProperty q =
new
CrmNumberProperty();
q.Name =
"quantity";
q.Value =
new
CrmNumber();
q.Value.Value =
Convert.ToInt32(quantity);
dy.Properties.Add(q);
//sales amount
//extendedamount
CrmMoneyProperty amountProp =
new
CrmMoneyProperty();
amountProp.Name =
"extendedamount";
amountProp.Value =
new
CrmMoney();
amountProp.Value.Value =
Convert.ToDecimal(salesamount);
// dy.Properties.Add(amountProp);
//sales price
//custom_salespriceperunit
CrmMoneyProperty price =
new
CrmMoneyProperty();
price.Name =
"custom_salespriceperunit";
price.Value =
new
CrmMoney();
price.Value.Value =
Convert.ToDecimal(salesprice);
//priceperunit
CrmMoneyProperty priceperunit =
new
CrmMoneyProperty();
priceperunit.Name =
"priceperunit" ;
priceperunit.Value =
new
CrmMoney();
// priceperunit.Value.Value = new decimal();
priceperunit.Value.Value = 0;
dy.Properties.Add(priceperunit);
TargetCreateDynamic target =
new
TargetCreateDynamic();
// Set the properties of the target object.
target.Entity = dy;
// Create the request object.
CreateRequest create =
new
CreateRequest();
// Set the properties of the request object.
create.Target = target;
// Execute the request.
CreateResponse created = (CreateResponse)crmservice.Execute(create);
}
catch (System.Web.Services.Protocols.SoapException
ee)
{
string r = (ee.Detail.InnerText +
" " );
}
catch (Exception
ee)
{
string r =(ee.Message +
" " );
}
thanks
Marwa Saleh