Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Bronze Elite Contributor
Posts: 1,989
Country: United_Kingdom
Message 1 of 11 (1,543 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
Employee
Posts: 1,163
Country: USA
Message 2 of 11 (1,516 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
Bronze Elite Contributor
Posts: 1,989
Country: United_Kingdom
Message 3 of 11 (1,514 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
Employee
Posts: 1,163
Country: USA
Message 4 of 11 (1,513 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
Highlighted
Bronze Elite Contributor
Posts: 1,989
Country: United_Kingdom
Message 5 of 11 (1,483 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
Copper Contributor
Posts: 99
Country: Canada
Message 6 of 11 (318 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

 

Copper Super Contributor
Posts: 386
Country: Australia
Message 7 of 11 (84 Views)

Re: How to add a product to an Opportunity?

Me to as this code works but actually creates a whole new product, how do utilise an existing product to link to the Opportunity

 

This is my current code

 

            // This example creates an Opportunity and then populates several of the Opportunities fields.
            // The Opportunity Variables
            OpportunityStatus oStatus = OpportunityStatus.Open;
            int iProbability = 50;
            DateTime dEstCloseDate = System.DateTime.Now.AddDays(15);
            Boolean bMakeItPrivate = false;
            string sName = "TEST Annuity";


            ContactList cList = Act.UI.ActApplication.Instance.ActFramework.Contacts.GetContacts(null);
            Contact cContact = cList[0];

            Guid[] gArray = new Guid[1];
            gArray[0] = c.ID;


            //Process[] pProcess = StageManager.ActiveProcesses[];
            Stage[] sStages = Act.UI.ActApplication.Instance.ActFramework.StageManager.Processes[0].Stages;
            Stage oStage = sStages[5];

            // Opportunity Products
            ProductList pList = Act.UI.ActApplication.Instance.ActFramework.Products.GetProducts(null);
            Product pProduct = pList[0];

            // Opportunity Variables used after its ceated
            string sReason = "Annuity policy has been linked to " + c.FirstName + c.LastName + " at and linked to either an ASA or Code.";
            DateTime dOpenDate = System.DateTime.Now;

            // Call to create opportunity
            Opportunity oOpp = Act.UI.ActApplication.Instance.ActFramework.Opportunities.CreateOpportunity(sName, oStatus, oStage, dEstCloseDate, bMakeItPrivate);
            oOpp.Probability = iProbability;
            oOpp.Reason = sReason;
            oOpp.UpdateContacts(gArray, null);
            oOpp.Update();

            // Call to add Product
            OpportunityProduct oProd = Act.UI.ActApplication.Instance.ActFramework.Products.OpportunityProductManager.CreateCustomEntity();
            oProd.Name = "TEST TEST";
            oProd.Quantity = 1;
            oProd.Cost = 0;
            oProd.Price = 1;
            oProd.Discount = 0;
            oProd.SetOpportunities(Act.UI.ActApplication.Instance.ActFramework.Opportunities.GetOpportunityAsOpportunityList(oOpp));
            oProd.Update();

            c.Update();

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s4
Copper Contributor
Posts: 99
Country: Canada
Message 8 of 11 (41 Views)

Re: How to add a product to an Opportunity?

I never figured out how to link an existing Opportunitiy Product to an Opportuntiy but I was able to copy the Opportunity Product to an Opportuntiy and then remove the Opportunity Product from the source Opportunity.

        public void moveOpportunityProduct(Opportunity sourceOpp, Opportunity targetOpp, OpportunityProduct sourceProd)
        {
            // create a new oppProd from sourceProd and associate it to targetOpp
            copyOpportunityProduct(targetOpp, sourceProd);
            // remove sourceProd using sourceOpp
            sourceOpp.UpdateProducts(null, new OpportunityProduct[] { sourceProd });
        }

        public void copyOpportunityProduct(Opportunity targetOpp, OpportunityProduct sourceProd)
        {
            // copy fields from source product, make new one and associate it to targetOpp
            OpportunityProduct newOppProd = actFwk.Products.OpportunityProductManager.CreateCustomEntity();
            newOppProd.Name = sourceProd.Name;
            newOppProd.ItemNumber = sourceProd.ItemNumber;
            newOppProd.ProductID = sourceProd.ProductID;
            newOppProd.Price = sourceProd.Price;
            newOppProd.Cost = sourceProd.Cost;
            newOppProd.Quantity = sourceProd.Quantity;
            newOppProd.Discount = sourceProd.Discount;

// some custom fields we have on products getOppProductFieldDescriptorByDisplayName("Associated Contact").SetValue(newOppProd, getOppProductFieldDescriptorByDisplayName("Associated Contact").GetValue(sourceProd)); getOppProductFieldDescriptorByDisplayName("Associated ContactID").SetValue(newOppProd, getOppProductFieldDescriptorByDisplayName("Associated ContactID").GetValue(sourceProd)); getOppProductFieldDescriptorByDisplayName("Previous Approval").SetValue(newOppProd, getOppProductFieldDescriptorByDisplayName("Previous Approval").GetValue(sourceProd)); getOppProductFieldDescriptorByDisplayName("Requested Years").SetValue(newOppProd, getOppProductFieldDescriptorByDisplayName("Requested Years").GetValue(sourceProd)); getOppProductFieldDescriptorByDisplayName("Approved Years").SetValue(newOppProd, getOppProductFieldDescriptorByDisplayName("Approved Years").GetValue(sourceProd)); getOppProductFieldDescriptorByDisplayName("isFurtherDollarsProduct").SetValue(newOppProd, getOppProductFieldDescriptorByDisplayName("isFurtherDollarsProduct").GetValue(sourceProd)); newOppProd.SetOpportunities(actFwk.Opportunities.GetOpportunityAsOpportunityList(targetOpp)); newOppProd.Update(); }


Not sure if that will help your situation or not.

-Eric

Copper Super Contributor
Posts: 386
Country: Australia
Message 9 of 11 (30 Views)

Re: How to add a product to an Opportunity?

thanks for that mate will check the code out and see what i can do, i did work out adding a product

 

It was this bit of code

 

                // Opportunity Products
                ProductList pList = Act.UI.ActApplication.Instance.ActFramework.Products.GetProducts(null);
                Product pProduct = pList[10];

It was a pain in the ... had to go through each number in the list to find each existing product and their code (37 in total), but it works and no duplicates, if you want the full code let me know

 

Now i am onto linking a Company, and completeting custom fields on the opportunity

 

I jsut had a quick look at your code looks liek you have done custome fields

 

 

 

 


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s4
Copper Contributor
Posts: 99
Country: Canada
Message 10 of 11 (25 Views)

Re: How to add a product to an Opportunity?

Yup I've done a little bit with them but I'm no expert though.

 

Feel free to private message me if you need a point in the right direction.