Community
Showing results for 
Search instead for 
Do you mean 
Reply

Adding Products to a Opportunity

Copper Contributor
Posts: 7
Country: United States

Adding Products to a Opportunity

I found Adding Products to an Opportunity to not be a straight forward process, and the Help file provided little guidance. This is a partial code sample that works. I hope this saves someone the hours I spent completing this seemingly simple task. Sorry about the formatting. Pasting loses the indenting for some reason.

ActFwk is a connected instantiation of the Act Framework. SqDetail is a RecordSet.

 

 

int itemCountTotal = SqDetail.Rows.Count; 

OpportunityProduct[] newProds = new OpportunityProduct[itemCountTotal];

Product oProd;

OpportunityProduct lineProd;

 

int itemCtr = 0;

foreach (DataRow drSqDetail in SqDetail.Rows)

{

.... 

THE CODE HERE JUST FILLED IN THE VARIABLES USED BELOW

....

 

oProd = ActFwk.Products.GetProduct(strProductName); 

if (oProd == null)

{

oProd = ActFwk.Products.CreateProduct(strProductName, strItemNumber, decListPrice, decItemCost);

}

 

lineProd = (
OpportunityProduct)ActFwk.Products.OpportunityProductManager.CreateEntity();

lineProd.ProductID = oProd.ID;

lineProd.Cost = decItemCost;

lineProd.Discount = decDiscount;

lineProd.ItemNumber = strItemNumber;

lineProd.Name = strProductName;

lineProd.Price = decListPrice;

lineProd.Quantity = decQuantity;

lineProd.Update();

 

newProds[itemCtr] = lineProd;

itemCtr++;

}

 

passedOpportunity.UpdateProducts(newProds, null);