Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Bronze Super Contributor
vivek
Posts: 1,817
Country: United_Kingdom
Message 1 of 6 (1,360 Views)
Accepted Solution

How to add a product to an Opportunity?

Hopefully someone can put me out of my misery! I seem to be going round in circles trying to work out how to add a product to an Opportunity.

 

To use the Opportunity.UpdateProducts(...) method you need an OpportunityProduct Object. I can get a Product Object via the ActApplication.ActFramework.Producsts.GetProductByName("myProduct"); But how on earth do I make the Product Object into a OpportunityProduct Object?

 

I presume that a OpportuityProduct SubEntity object is a wrapper or abstraction object to the Product and each OpportunityProduct has a unique ID that is associated with an Opportunity object and is different to a Product ID.

 

Can someone let me know if it is possible to add a product to a Opportunity with the new ACT! 2010 SDK It used to be a fairly straight forward procedure previously but my brain is tied up in knots now!

 

Yours very confused,

 

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Please use plain text.
Employee
mwood
Posts: 1,163
Country: USA
Message 2 of 6 (1,332 Views)

Re: How to add a product to an Opportunity?

George recently posted something on getting products for opportunities, let me know if that helps, if not I have a few product samples I can probably pull from.

 

Here is his post.

Matthew Wood
Act! SDK Support
Community Moderator
Please use plain text.
Bronze Super Contributor
vivek
Posts: 1,817
Country: United_Kingdom
Message 3 of 6 (1,330 Views)

Re: How to add a product to an Opportunity?

Hiya Matthew,

 

Thanks for the quick reply and link.

 

I had a look through the code that George had posted but the problem is I am attempting to create a new OpportunityProduct Object i.e. I have a new Opportunity object and would like to add Products to that new Opp.

 

The Opportunity.UpdateProducts method only takes OpportunityProduct objects and I can not find any way to convert a Product to a OpportunityProduct, if that makes any sense! haha

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Please use plain text.
Employee
mwood
Posts: 1,163
Country: USA
Message 4 of 6 (1,329 Views)

Re: How to add a product to an Opportunity?

This sample adds a new OpportunityProduct to the current opportunity

 

Opportunity o = ActApp.ApplicationState.CurrentOpportunity;

            OpportunityProduct oppProd = ActApp.ActFramework.Products.OpportunityProductManager.CreateCustomEntity();
            oppProd.Name = "Test Prod";
            oppProd.Quantity = 1;
            oppProd.Cost = 100;
            oppProd.Price = 50;
            oppProd.Discount = 0;
            oppProd.SetOpportunities(ActApp.ActFramework.Opportunities.GetOpportunityAsOpportunityList(o));
            oppProd.Update();

Matthew Wood
Act! SDK Support
Community Moderator
Please use plain text.
Bronze Super Contributor
vivek
Posts: 1,817
Country: United_Kingdom
Message 5 of 6 (1,299 Views)

Re: How to add a product to an Opportunity?

Thanks Matthew, that did the trick. For some reason I just had not noticed the strange OpportunityProductManager property, mind you I dont think I would have guessed that that was the way forward

Cheers once again
Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Please use plain text.
Copper Contributor
e_hoog
Posts: 69
Country: Canada
Message 6 of 6 (134 Views)

Re: How to add a product to an Opportunity?

Quick question.

When you are assigning an existing Product to an existing Opportunity, I see there is OpportunityProduct type and understand how you set this but where does the Product type come into play?

 


I can get an existing product like this:

Product dtcProduct = actFwk.Products.GetProductByName("01 DTC");

 


Would you then use that Product "template" to assign a new OpportunityProduct like:

 

Product dtcProduct = actFwk.Products.GetProductByName("01 DTC");

OpportunityProduct dtcOppProduct = actFwk.Products.OpportunityProductManager.CreateCustomEntity()

        dtcOppProduct.Name = dtcProduct.Name;

        dtcOppProduct.Quantity = 10;

        dtcOppProduct.SetOpportunities(actFwk.Opportunities.GetOpportunityAsOpportunityList(opp));          

        dtcOppProduct.Update();

Hope someone can shed a little light for me.  Much appreciated.

-Eric

 

Please use plain text.