Community
Showing results for 
Search instead for 
Do you mean 
Reply

actApplication_CurrentOpportunityChanged fires multiple times

Accepted Solution Solved
Champion Listener
Posts: 32
Country: Canada
Accepted Solution

actApplication_CurrentOpportunityChanged fires multiple times

 Hello,

 

I'm working on Act plugin for opportunities. I have Act! Premium Version 18.0.501.0, Update 6. The plugin should create a tab in opportunities and there should be a datagrid with some data. Whenever opportunity stage is changed, grid should update and load new values. I was using Act.DevNet.CustomSubEntitiesSample and their Policy as an example. However, the event actApplication_CurrentOpportunityChanged fires so many times that a visible blinking and freezing of Act is noticeable for a few seconds. From my log - it appears that this event fires hundreds of times. Values in databases are added fine.

I spent a lot of time trying to figure out what i'm doing wrong, but wasn't able to find why this happens. The event fires multiple times when this line executes:

 

mySubEntity = this.bindingSource1.AddNew() as MySubEntity

 

Here is my code:

 

void Application_AfterLogon(object sender, EventArgs e)
{
.....
this.actApplication = actApplication;
.....
if ((parentEntity & ParentEntity.Opportunities) == ParentEntity.Opportunities)
     this.actApplication.CurrentOpportunityChanged += new EventHandler(actApplication_CurrentOpportunityChanged);
.....
}


void actApplication_CurrentOpportunityChanged(object sender, EventArgs e)
{
this.actApplication.ApplicationState.CurrentOpportunity.Fields.FieldChanged += new MutableEntity.FieldCollection.FieldChangedHandler(Fields_FieldChanged);
log.Debug("actApplication_CurrentOpportunityChanged");
try
{
if (currentOpportunity != null && currentOpportunity.ID != this.actApplication.ApplicationState.CurrentOpportunity.ID)
    LoadGridData();
}
catch (Exception ex)
{
log.Error("actApplication_CurrentOpportunityChanged: " + ex.Message, ex);
}

}


private void LoadGridData()
{
try
{
this.subEntityDataGridView.DataSource = null;
this.subEntityDataGridView.Refresh();

if (actApplication != null && this.actApplication.ActFramework.IsLoggedOn)
{
// Get the current opp.
currentOpportunity = this.actApplication.ApplicationState.CurrentOpportunity;
if (currentOpportunity != null)
{
currentStage = currentOpportunity.Stage;
currentProcess = currentStage.Process;

CustomSubEntityManager<MySubEntity> manager = this.actApplication.ActFramework.CustomEntities.GetSubEntityManager<MySubEntity>(descriptor);

if (manager != null)
{
myEntitiesList = getMyEntities(selectedFilterIndex, manager, currentStage);

if (myEntitiesList != null && myMgrEntitiesList.Count > 0)
{

// Add the fields we want to display in the grid to field descriptor collection.
myEntitiesList.FieldDescriptors.Add(manager.GetCustomEntityFieldDescriptor(CustomSubEntityDefinition.MY_FIELD1, Act.Framework.MutableEntities.FieldNameType.Alias));
myEntitiesList.FieldDescriptors.Add(manager.GetCustomEntityFieldDescriptor(CustomSubEntityDefinition.MY_FIELD2, Act.Framework.MutableEntities.FieldNameType.Alias));
myEntitiesList.FieldDescriptors.Add(manager.GetCustomEntityFieldDescriptor(CustomSubEntityDefinition.MY_FIELD3, Act.Framework.MutableEntities.FieldNameType.Alias));
myEntitiesList.FieldDescriptors.Add(manager.GetRecordManagerFieldDescriptor());
myEntitiesList.FieldDescriptors.Add(manager.GetRecordLastEditorFieldDescriptor());

this.bindingSource1.DataSource = myEntitiesList;

this.subEntityDataGridView.DataSource = this.bindingSource1;
}
else
{
myEntitiesList.FieldDescriptors.Add(manager.GetCustomEntityFieldDescriptor(CustomSubEntityDefinition.MY_FIELD1, Act.Framework.MutableEntities.FieldNameType.Alias));
myEntitiesList.FieldDescriptors.Add(manager.GetCustomEntityFieldDescriptor(CustomSubEntityDefinition.MY_FIELD2, Act.Framework.MutableEntities.FieldNameType.Alias));
myEntitiesList.FieldDescriptors.Add(manager.GetCustomEntityFieldDescriptor(CustomSubEntityDefinition.MY_FIELD3, Act.Framework.MutableEntities.FieldNameType.Alias));
myEntitiesList.FieldDescriptors.Add(manager.GetRecordManagerFieldDescriptor());
myEntitiesList.FieldDescriptors.Add(manager.GetRecordLastEditorFieldDescriptor());

this.bindingSource1.DataSource = myEntitiesList;

this.subEntityDataGridView.DataSource = this.bindingSource1;

initMyEntityList(myEntitiesList.Count);
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}


private void initMyEntityList(int count)
{

try
{
myProcess = getProcess(actProcess.ID.ToString());
if (myProcess != null)
{
myStage = getStage(myProcess, actStage.ID.ToString());
if (myStage != null)
{
if (myStage.StageStepsList != null)
{
for (int k = myStage.StageStepsList.Length - 1; k >= 0; k--)
{
myStep = myStage.StageStepsList[k];
if (myStep != null)
{
mySubEntity = null;

if (count > 0)
mySubEntity = this.bindingSource1.Current as MySubEntity;

if (mySubEntity == null)
mySubEntity = this.bindingSource1.AddNew() as MySubEntity;    //this is the line that causes cascading events. if i comment the line, only one row is added in the data grid in my custom tab and this is not what i want

............
mySubEntity.Update();

}
}
}
}
}
}
catch (Exception e)
{
log.Error("Error initializing MyEntityList: " + e.Message, e);
}

}

void Fields_FieldChanged(string fieldName)
{
if (fieldName.Equals("TBL_OPPORTUNITY.STAGEID"))
{
..........
}
}

 

Can anyone tell me what is going on here? Any help will be greatly appreciated.

 

Thanks.

Katerina


Accepted Solutions
Solution
Accepted by topic author Katerina
‎04-15-2016 05:38 AM
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: actApplication_CurrentOpportunityChanged fires multiple times

I don't think its you at all. I reported the opp list refreshing multiple times way back in ACT! 2010 (?) when they promoted the opportunity entity.

 

 

I sent/spoke/cornered at trade show many developers and SDK personnel but either I hit a brick wall or when I finally get a " Oh yeah, I see the issue..." that employees leaves the company.

 

Good luck.

-- Jim Durkin

 

 

View solution in original post


All Replies
Solution
Accepted by topic author Katerina
‎04-15-2016 05:38 AM
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: actApplication_CurrentOpportunityChanged fires multiple times

I don't think its you at all. I reported the opp list refreshing multiple times way back in ACT! 2010 (?) when they promoted the opportunity entity.

 

 

I sent/spoke/cornered at trade show many developers and SDK personnel but either I hit a brick wall or when I finally get a " Oh yeah, I see the issue..." that employees leaves the company.

 

Good luck.

-- Jim Durkin

 

 

Copper Contributor
Posts: 123
Country: Canada

Re: actApplication_CurrentOpportunityChanged fires multiple times

I use Act Premium 2013 and I also notice this happening.  I removed all of my plugins and checked turned up the verbosity of the Act Logs and I could see this event firing multiple times as well.

I never really tried to do anything about it but i'm sure there's some way for you to make some sort of counter that makes your function only run once and then reset the counter when the opportunity changes.  Just a thought!

-Eric

Champion Listener
Posts: 32
Country: Canada

Re: actApplication_CurrentOpportunityChanged fires multiple times

Thanks Jim and Eric.

Yes, I have a workaround for my code and it runs only once, but refreshing, blinking is still there. 

Employee
Posts: 34
Country: USA

Re: actApplication_CurrentOpportunityChanged fires multiple times

This is fixed in 18.2 update 1.  Please let us know if you continue to have issues. 

Champion Listener
Posts: 32
Country: Canada

Re: actApplication_CurrentOpportunityChanged fires multiple times

Yes, this is fixed now in 18.2 update 1. Thanks. But there is another problem now. 

 

It appears the Fields_FieldChanged event doesn't fire always when field is changed. 

 

void actApplication_CurrentOpportunityChanged(object sender, EventArgs e)
{
this.actApplication.ApplicationState.CurrentOpportunity.Fields.FieldChanged +=                               new MutableEntity.FieldCollection.FieldChangedHandler(Fields_FieldChanged);

................

}

 

I need to update data in my Custom subentity tab control when Stage is updated/changed. Previously, event was firing and based on the field name I was able to detect when Stage was updated. Now, this event doesn't fire.

 

Has anything been changed here? How can i detect when Stage is updated?

 

Thanks.

Katerina