Community
Showing results for 
Search instead for 
Do you mean 
Reply

Opportunity Plugin

Tuned Listener
Posts: 23
Country: United Kingdom

Opportunity Plugin

I am putting together a plugin and I would like to get the ID from the current opportunity when the user closes the opportunity I want this to query the opportunities database.  Do you have some sample code to achieve this.

Regards,

Joe

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Opportunity Plugin

[ Edited ]

 

You can use the CurrentOpportunity to get information such as all the products attached to the current opportunity.

 

Dim cOpportunity As Act.Framework.Opportunities.Opportunity = Nothing
cOpportunity = ACTApplication.ApplicationState.CurrentOpportunity
For Each cProduct As Act.Framework.Opportunities.OpportunityProduct In cOpportunity.GetProducts(Nothing)
    MessageBox.Show(cProduct.Name)
Next
Dim ID as Guid = cOpportunity.ID

Hope this helps

-- Jim Durkin

 

Tuned Listener
Posts: 23
Country: United Kingdom

Re: Opportunity Plugin

Hi Jim,

Thanks for your suggestion which I have attempted to implement using an example of yours as:

At class level:

Friend HostApplication As ActApplication

 

On the load event of the plugin:

Friend Sub OnLoad(ByVal App As ActApplication) Implements IPlugin.OnLoad

AddHandler HostApplication.CurrentOpportunityChanged, AddressOf HostApplication_OpportunityUpdated

End Sub

 

 

On the opportunity updated event:

Private Sub HostApplication_OpportunityUpdated()

 

Try

            Dim o As Opportunity = HostApplication.ApplicationState.CurrentOpportunity

 

            If o.State = Act.Framework.EntityState.Modified Then

                Dim ID As Guid = o.ID

MsgBox(ID.ToString) ‘This throws an error ‘object reference not set……’

 

   End If

 

        Catch ex As Exception

            MsgBox(Err.Description)

        End Try

    End Sub

 

Can you tell me the correct approach.

Regards,

Joe

 

 

 

 

 

Tuned Listener
Posts: 23
Country: United Kingdom

Re: Opportunity Plugin

Hi,

 

Can anyone help me with this, I want to capture the status change event when the user updates the opportunity to  'won' but I am breaking ACT with this code and can't find why.

 

Regards,

Joe

 

Private

Sub HostApplication_CurrentViewChanged(ByVal Sender AsObject, ByVal e As System.EventArgs)

       

 

       

       

Try

           

If HostApplication.CurrentViewName = "Act.UI.IOpportunityView"Then

               

Dim Intret AsInteger

               

Dim o AsOpportunity = HostApplication.ApplicationState.CurrentOpportunity

               

If o.Status = OpportunityStatus.Won Then

                   

'Do work

           

               

EndIf

           

EndIf

       

Catch ex AsException

       

EndTry

 

   

EndSub

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Opportunity Plugin

You have this code in the CurrentViewChanged event.

 

ACT may not have initialized the current opportunity until after the view is loaded?

 

-- Jim Durkin

Tuned Listener
Posts: 23
Country: United Kingdom

Re: Opportunity Plugin

Hi Jim,

I originally had the event in the CurrentOpportunityChanged event with exactly the same result! This should not be that difficult to achieve. Do you have any working code to achieve the required result.

Regards,

Joe

 

AddHandler HostApplication.CurrentOpportunityChanged, AddressOf HostApplication_OpportunityUpdated

 

Private Sub HostApplication_OpportunityUpdated(ByVal Sender As Object, ByVal e As System.EventArgs)

        Try

            Dim Intret As Int16 = 0

 

 

            If HostApplication.CurrentViewName = "Act.UI.IOpportunityView" Then

 

                Dim o As Opportunity = HostApplication.ApplicationState.CurrentOpportunity

 

                If o.Status = OpportunityStatus.Won Then

                    End If

 

                Else

 

                End If

            End If

 

Catch ex As Exception

            MsgBox(Err.Description)

        End Try

    End Sub

 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Opportunity Plugin

Joe,

 

I copied your code into a project and it did not error.

The CurrentOpportunity was valid.

 

I am using VS 2008.

Compile against C:\DurkinComputing V4\ACT Assemblies\12.0.409\Act.UI.dll

ACT! 2012.1.108 installed

 

Thanks

-- Jim

Tuned Listener
Posts: 23
Country: United Kingdom

Re: Opportunity Plugin

Hi Jim,

 

Thanks for your reply, I am still getting the error when I change the the opportunity status. This is on a development machine running windows7 and ACT! 2012.1.108. I will trial the code on the server tommorrow to see if I get the same result.

 

Regards,

Joe

Tuned Listener
Posts: 23
Country: United Kingdom

Re: Opportunity Plugin

Hi Jim,

 

I have tried the code against the working application and I get the same error. We have ACT 2012 Premium installed and I am using Visual Studio 2010 to build the plugin. Would you please send me a copy of your working project so that I can test it against my ACT installation.

 

Regards,

Joe

Nickel Contributor
Posts: 175
Country: USA

Re: Opportunity Plugin

Joe,

Seeing that you are using VS 2010, you may want to check your target framework in the project properties. Make sure you are targeting "Framework 4.0" not "Framework 4.0 Client". I believe ACT requires the full framework. I know to check this due to other programs I've written with things that need the full framework. Hope this helps.