Friday, July 17, 2009

Add Invoice to Product in CRM 4.0 with write in existing Product

Guid productId = new Guid(productid);
invoicedetail objDetails = new invoicedetail();
objDetails.productid = new Lookup();
objDetails.productid.Value = productId;
objDetails.productid.type = EntityName.product.ToString();
//if (!string.IsNullOrEmpty(product.description))
//{
// objDetails.description = product.description.ToString();
//}

CrmDecimal objDec = new CrmDecimal();
objDec.Value = Convert.ToDecimal("1", CultureInfo.InvariantCulture);
objDetails.quantity = objDec;

CrmMoney objDec1 = new CrmMoney();
objDec1.Value = Convert.ToDecimal(allocatedAmount, CultureInfo.InvariantCulture);
objDetails.priceperunit = objDec1;
objDetails.invoiceid = new Lookup();
objDetails.invoiceid.Value = invoiceId;
objDetails.invoiceid.type = EntityName.invoice.ToString();
CrmBoolean objOverride = new CrmBoolean();
objOverride.Value = true;//
objDetails.ispriceoverridden = objOverride;
CrmBoolean objProductOverride = new CrmBoolean();
objProductOverride.Value = false;//
// objDetails.ispriceoverridden = objOverride;
objDetails.isproductoverridden = objProductOverride;
objDetails.uomid = new Lookup();
objDetails.uomid.Value = new Guid(RetrieveUog());
objDetails.uomid.type = EntityName.uom.ToString();
service.Create(objDetails);

No comments: