Community
Showing results for 
Search instead for 
Do you mean 
Reply

Get selected opportunity

Accepted Solution Solved
Copper Contributor
Posts: 11
Country: Netherlands
Accepted Solution

Get selected opportunity

Hi all, im trying to get the current selected opportunity from the opportunity list but i keep getting a "object reference not set to an instance of an object"

 

I used the  custommenuplugin example:

 

private void DoStuff(string command)

        {

            OpportunityList opplist = this.application.ApplicationState.CurrentOpportunities;

            if (opplist.Count > 0)

            {

                Opportunity opp = opplist[0];

                MessageBox.Show(opp.Name);       

            }

        } 

 

it appears opplist is null. Is there an other way to get the current selected opportunity? 


Accepted Solutions
Solution
Accepted by topic author RvdK
‎09-25-2015 03:20 AM
Nickel Super Contributor
Posts: 441
Country: UK

Re: Get selected opportunity

I have had problems with this in the past.  In v10 the only way I know to do it is to cycle through all the controls under actapp until you find the grid.  Once you have that you can find the selected items... the sample below is for getting the selected activity in the task list but its essentially the same, hopefully you can us it as a starting point,

 

Public Sub Test01(ByVal s As String)

If ActApp.CurrentViewName = "Act.UI.ITaskView" Then

Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = FindGrid(ActApp)

Dim ids As New ArrayList

Dim activity As Act.Framework.Activities.Activity

For Each row As C1.Win.C1FlexGrid.Row In grid.Rows.Selected

activity = row.DataSource

ids.Add(activity.ActivityId)

Next

Dim aList As Act.Framework.Activities.ActivityList = ActApp.ActFramework.Activities.GetActivityInstancesByActivityId(ids.ToArray(GetType(System.Guid)))

MsgBox(aList.Count)

End If

End Sub

 

Public Function FindGrid(ByVal parent As Control) As C1.Win.C1FlexGrid.C1FlexGrid

Static grid As C1.Win.C1FlexGrid.C1FlexGrid

For Each ctrl As Control In parent.Controls

If ctrl.GetType.ToString = "C1.Win.C1FlexGrid.C1FlexGrid" Then

grid = ctrl

Return grid

End If

If grid Is Nothing Then

If ctrl.Controls.Count > 0 Then

FindGrid(ctrl)

End If

End If

Return grid

Next

End Function

 

 

Tom

 

View solution in original post


All Replies
Nickel Super Contributor
Posts: 441
Country: UK

Re: Get selected opportunity

Hi,

What version of act, currently selected where?

 

Tom

Copper Contributor
Posts: 11
Country: Netherlands

Re: Get selected opportunity

ACT! 2008 (v10), opportunity selected in opportunity list.
Solution
Accepted by topic author RvdK
‎09-25-2015 03:20 AM
Nickel Super Contributor
Posts: 441
Country: UK

Re: Get selected opportunity

I have had problems with this in the past.  In v10 the only way I know to do it is to cycle through all the controls under actapp until you find the grid.  Once you have that you can find the selected items... the sample below is for getting the selected activity in the task list but its essentially the same, hopefully you can us it as a starting point,

 

Public Sub Test01(ByVal s As String)

If ActApp.CurrentViewName = "Act.UI.ITaskView" Then

Dim grid As C1.Win.C1FlexGrid.C1FlexGrid = FindGrid(ActApp)

Dim ids As New ArrayList

Dim activity As Act.Framework.Activities.Activity

For Each row As C1.Win.C1FlexGrid.Row In grid.Rows.Selected

activity = row.DataSource

ids.Add(activity.ActivityId)

Next

Dim aList As Act.Framework.Activities.ActivityList = ActApp.ActFramework.Activities.GetActivityInstancesByActivityId(ids.ToArray(GetType(System.Guid)))

MsgBox(aList.Count)

End If

End Sub

 

Public Function FindGrid(ByVal parent As Control) As C1.Win.C1FlexGrid.C1FlexGrid

Static grid As C1.Win.C1FlexGrid.C1FlexGrid

For Each ctrl As Control In parent.Controls

If ctrl.GetType.ToString = "C1.Win.C1FlexGrid.C1FlexGrid" Then

grid = ctrl

Return grid

End If

If grid Is Nothing Then

If ctrl.Controls.Count > 0 Then

FindGrid(ctrl)

End If

End If

Return grid

Next

End Function

 

 

Tom

 

Copper Contributor
Posts: 11
Country: Netherlands

Re: Get selected opportunity

[ Edited ]
Thanks TDavis! I got it working. It's a shame its a bit of a workaround compairing to the easy fetch of contact/group and opportunities. 
 
private C1.Win.C1FlexGrid.C1FlexGrid FindGrid(Control container)
{
if (container.GetType().ToString() == "C1.Win.C1FlexGrid.C1FlexGrid")
{
return (C1.Win.C1FlexGrid.C1FlexGrid)container;
}

foreach (Control ctrl in container.Controls)
{
C1.Win.C1FlexGrid.C1FlexGrid foundctrl = FindGrid(ctrl);
if (foundctrl != null)
{
return foundctrl;
}
}
return null;
}

private void DoStuff(string command)
{
if (application.CurrentViewName == "Act.UI.IOpportunityView")
{
C1.Win.C1FlexGrid.C1FlexGrid grid = FindGrid(application);
if (grid != null)
{
List<Opportunity> opportunities = new List<Opportunity>();
foreach (C1.Win.C1FlexGrid.Row row in grid.Rows.Selected)
{
opportunities.Add((Opportunity)row.DataSource);
}

//do something with opportunity
}
else
{
MessageBox.Show("grid not found");
}
}
}
Message Edited by RvdK on 10-02-2009 07:47 AM