Developer's Forum
Register  ·  Sign In  ·  Help
Jump to Page:   1
  Reply   Reply  

Assigning an OpportunityProduct to a new Opportunity prgrammatically using the SDK
Options    Options  
RobNighti…
Copper Contributor
Posts: 7


RobNightingale

Country: United Kingdom

Message 1 of 5

Viewed 780 times


Hi All,

 

I have been developing a tool that will allow the import of opportunities on mass.

I have successfully performed all tasks including user lookup, stage and process lookup, all data assignment etc.

 

I am struggling, however, to populate and assign an OpportunityProduct object to the newly created Opportunity Object.

 

I assume the code to do this will follow the following structure:

 

//create the Opportunity object

Opportunity newOpp = framework.Opportunities.CreateOpportunity();

 

//assign all the fields etc to the opportunity

newOpp.Fields[fieldName, true] = value;

 

I can create a product using

Product newProd = framework.Products.CreateProduct(name, item, price, cost);

 

I also know you update the associated OpportunityProducts of an Opportunity using the following

newOpp.UpdateProducts(new OpportunityProduct[] {productToAdd},new OpportunityProduct[] {}); 

 

I know there is an Product Manager and OpportunityProductManager

framework.Products

framework.Products.OpportunityProductManager

 

and an OpportunityProduct Constructor although I have no idea how to use the associated state parameter!!

public OpportunityProduct( 
   CustomSubEntity.CustomSubEntityInitializationState state

 

 I would appreciate any help in constructing a newOpportunityProduct and attaching it to an Oportunity.

 

Many Thanks,

 

Rob.

 

 

Kudos!
Solved!
Go to the Solution
Go to Solution
10-15-2009 02:59 AM
 
  Reply   Reply  

Re: Assigning an OpportunityProduct to a new Opportunity prgrammatically using the SDK
Options    Options  
hugovale
Copper Super Contributor
Posts: 53


hugovale

Country: USA

Message 2 of 5

Viewed 766 times


Hi Rob,

 

The method I use to add a product to an opportunity is:

 

newOpportunity.AddProduct("Test Name", "Test Item Number", 0D, 0D, 0, 0D)

 

Hope it helps

 


 

Hugo Vale
Datastream Custom Solutions
http://www.datastreamcs.com
Kudos!
10-15-2009 02:00 PM
 
  Reply   Reply  

Re: Assigning an OpportunityProduct to a new Opportunity prgrammatically using the SDK
Options    Options  
RobNighti…
Copper Contributor
Posts: 7


RobNightingale

Country: United Kingdom

Message 3 of 5

Viewed 747 times


Thanks for the reply but I have just checked and this method is not available on the ACT 2010 version of the SDK, I fear I may have an early beta version of the SDK as I downloaded it about 6 weeks ago and I am currently trying to chase down the development team as the download site seems to be broken.

 

Thanks for the reply though Hugovale, what SDK version /version of ACT are you using?

 

Rob.

Kudos!
10-21-2009 01:44 AM
 
  Reply   Reply  

Re: Assigning an OpportunityProduct to a new Opportunity prgrammatically using the SDK
Options    Options  
Tdavis
Nickel Super Contributor
Posts: 441


Tdavis

Country: UK

Message 4 of 5

Viewed 727 times


Products are a custom entity now... I have tried to get it to work for you but I always get an error on saving the product, maybe someone will be able to help; I have tried 2 ways, using data bindings and without...

 

 No data bindings:

 

'create the opp Dim opp As Act.Framework.Opportunities.Opportunity = ActApp.ActFramework.Opportunities.CreateOpportunity() opp.UpdateContacts(New Guid() {ActApp.ApplicationState.CurrentContact.ID}, Nothing) opp.Name = "test" opp.Update() 'create the product Dim product As Act.Framework.Opportunities.OpportunityProduct = _ ActApp.ActFramework.Products.OpportunityProductManager.CreateCustomEntity product.SetOpportunities(ActApp.ActFramework.Opportunities.GetOpportunityAsOpportunityList(opp)) 'set a name product.Name = "test" 'save the product product.Update() '<<<<-----error saving here

 

 

 

Data bindings:

 

'create the opp Dim opp As Act.Framework.Opportunities.Opportunity = ActApp.ActFramework.Opportunities.CreateOpportunity() opp.UpdateContacts(New Guid() {ActApp.ApplicationState.CurrentContact.ID}, Nothing) opp.Name = "test" opp.Update() 'get the current product list for the opp Dim plist As Act.Framework.CustomEntities.CustomEntityList(Of Act.Framework.Opportunities.OpportunityProduct) = _ opp.GetProducts(Nothing) 'add the fields For Each field As Act.Framework.ComponentModel.DBFieldDescriptor In ActApp.ActFramework.Products.OpportunityProductManager.GetFieldDescriptors() plist.FieldDescriptors.Add(field) Next 'create a binding source and bind to the product list Dim bindingsource As New BindingSource bindingsource.DataSource = plist 'create the product Dim product As Act.Framework.Opportunities.OpportunityProduct = _ bindingsource.AddNew() product.SetOpportunities(ActApp.ActFramework.Opportunities.GetOpportunityAsOpportunityList(opp)) 'set the contacts, companies and groups Try product.SetCompanies(opp.GetCompanies(Nothing)) Catch ex As Exception End Try Try product.SetGroups(opp.GetGroups(Nothing)) Catch ex As Exception End Try Try product.SetContacts(opp.GetContacts(Nothing)) Catch ex As Exception End Try product.Name = "test" 'save the product product.Update() '<<<--- error svaing product here

 

 Tom

 

1
Kudos!
10-21-2009 08:35 AM
 
  Reply   Reply  

Re: Assigning an OpportunityProduct to a new Opportunity prgrammatically using the SDK
Options    Options  
RobNighti…
Copper Contributor
Posts: 7


RobNightingale

Country: United Kingdom

Message 5 of 5

Viewed 628 times


Tom, You Sir are a legend!

 

I have just got time to play with just the first section of your code and I used the following simple code:

 

Opportunity opp = framework.Opportunities.CreateOpportunity(); opp.Name = "ROBTEST"; opp.Update(); OpportunityProduct oppProd = framework.Products.OpportunityProductManager.CreateCustomEntity(); oppProd.Name = "ROBTESTPROD"; oppProd.Quantity = 2.00m; oppProd.Cost = 53.00m; oppProd.Price = 65.00m; oppProd.Discount = 0.00m; oppProd.SetOpportunities(framework.Opportunities.GetOpportunityAsOpportunityList(opp)); oppProd.Update();

 

I did receive errors at the point you stated "oppProd.Update" but the InnerException just stated that the various values for Cost, Quantity etc could not accept null values and therefore need explicity setting!

 

After editing this so that all the necessary variables are completed I can add whatever product I want!

 

It seems so simple when you look back!!!!!

 

Thanks again for your help.

 

Rob.

 

 

Kudos!
Accepted Solution
Accepted Solution
11-02-2009 03:01 AM
 
Jump to Page:   1