Community
Showing results for 
Search instead for 
Do you mean 
Reply

Field Changed Event handler don't fire when view change but not contact

Accepted Solution Solved
Tuned Listener
Posts: 17
Country: France
Accepted Solution

Field Changed Event handler don't fire when view change but not contact

hi,

 

I have a problem.

I want to fire an Event when a field is changed but when i switch to List view and come back to Detail View the event handler don't fire.

 

        void IPlugin.OnLoad(ActApplication application)//au chargement
        {
            this.application = application;
            
            
            application.AfterLogon += new EventHandler(Application_AfterLogon);
            application.BeforeLogoff += new EventHandler(Application_BeforeLogoff);
            application.CurrentOpportunityChanged += new EventHandler(application_CurrentOpportunityChanged);
            application.CurrentViewChanged+=application_CurrentViewChanged;
            ACTFM = application.ActFramework;
        }

        private void application_CurrentViewChanged(object sender, EventArgs e)
        {
            if (application.CurrentViewName == typeof(Act.UI.IContactDetailView).FullName)
            {
                // attach events
                application.CurrentContactChanged += application_CurrentContactChanged;
                application.CurrentContactChanging += application_CurrentContactChanging;
                application.ApplicationState.CurrentContact.Fields.FieldChanged += Fields_FieldChanged;
            }
            else
            {
                // detatch events
                Contact contact = application.ApplicationState.CurrentContact;

                if (contact != null)
                {
                    application.CurrentContactChanged -= application_CurrentContactChanged;
                    application.CurrentContactChanging -= application_CurrentContactChanging;
                    application.ApplicationState.CurrentContact.Fields.FieldChanged -= Fields_FieldChanged;
                }
            }

        }

        private void application_CurrentContactChanging(object sender, EventArgs e)
        {
            application.ApplicationState.CurrentContact.Fields.FieldChanged -= Fields_FieldChanged;
           
        }


        private void application_CurrentContactChanged(object sender, EventArgs e)//au changement de contact dans act
        {
            var c = application.ApplicationState.CurrentContact;
            cs.ListRegistrationUpdate();
            cs.SetValues();
            cs.MiseAJour(c);
            cs.SetValues();
            c.Fields.FieldChanged += Fields_FieldChanged;
        }

        private void Fields_FieldChanged(string fieldName)
        {
            MessageBox.Show("Field Changed");
        }

 

 


Accepted Solutions
Solution
Accepted by topic author joeysssful
‎09-25-2015 03:20 AM
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Field Changed Event handler don't fire when view change but not contact

If you are using your original code posted it does not include the refresh.

 

this.ACTApplication.RefreshView(this.ACTApplication.CurrentViewName);

 

-- Jim Durkin

 

View solution in original post


All Replies
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Field Changed Event handler don't fire when view change but not contact

I think its still a bug in ACT!.

 

Try walking off the startup record. Does the event fire now?

 

http://community.act.com/t5/Act-Developer-s-Forum/Contact-Field-Changes/m-p/64724/highlight/true#M25...

 

 

-- Jim Durkin

Tuned Listener
Posts: 17
Country: France

Re: Field Changed Event handler don't fire when view change but not contact

Sorry but I dont't understand what you want to say?? 

"Try walking off the startup record. Does the event fire now?"

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Field Changed Event handler don't fire when view change but not contact

Start ACT!

Go to the Contact Details view

Click on the "Go to next contact >|" button to move to the next record.

 

Does the event fire now?

 

Tuned Listener
Posts: 17
Country: France

Re: Field Changed Event handler don't fire when view change but not contact

Yep it works. 

 

On your link I saw "force a refresh/save as soon as the database has opened and from that point forward all event should fire normally."

But I don't know how to...

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Field Changed Event handler don't fire when view change but not contact

This will refresh the currently loaded view

 

this.ACTApplication.RefreshView(this.ACTApplication.CurrentViewName);

 

 

-- JIm Durkin

Tuned Listener
Posts: 17
Country: France

Re: Field Changed Event handler don't fire when view change but not contact

It doesn't change anything, when I change contact it works but when I change view and not contact it continue to doesn't work...

 

 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Field Changed Event handler don't fire when view change but not contact

This code is ripped out of Impact Suite. Not positive it will run out-of-the-boc but it should give you direction.

    Private Sub RefreshCurrentView(ByVal Sender As Object, ByVal e As System.EventArgs)
   
        '-----------------------------------------------------
        ' Add the current event handlers
        '-----------------------------------------------------
        Try
            Select Case HostApplication.CurrentViewName
                Case Durkin.Common.Classes.ACTUIToolkit.ACTViews.ContactDetailViewName
                    If Me.UIMathEventLoadedContacts = False Then
                        If Not (Me.HostApplication.ApplicationState.CurrentContact Is Nothing) Then
                            Me.UIMathEventLoadedContacts = True
                            AddHandler Me.HostApplication.CurrentContactChanged, AddressOf Math_CurrentContactChanged
                        End If
                    End If

                Case Durkin.Common.Classes.ACTUIToolkit.ACTViews.CompanyDetailViewName
                    If Me.UIMathEventLoadedCompanies = False Then
                        If Not (Me.HostApplication.ApplicationState.CurrentCompany Is Nothing) Then
                            Me.UIMathEventLoadedCompanies = True
                            AddHandler Me.HostApplication.CurrentCompanyChanged, AddressOf Math_CurrentCompanyChanged
                        End If
                    End If

                Case Durkin.Common.Classes.ACTUIToolkit.ACTViews.GroupDetailViewName
                    If Me.UIMathEventLoadedGroups = False Then
                        If Not (Me.HostApplication.ApplicationState.CurrentGroup Is Nothing) Then
                            Me.UIMathEventLoadedGroups = True
                            AddHandler Me.HostApplication.CurrentGroupChanged, AddressOf Math_CurrentGroupChanged
                        End If
                    End If

                Case Durkin.Common.Classes.ACTUIToolkit.ACTViews.OpportunityDetailViewName, Durkin.Common.Classes.ACTUIToolkit.ACTViews.OpportunityViewName
                    If Me.UIMathEventLoadedOpportunities = False Then
                        If Not (Me.HostApplication.ApplicationState.CurrentOpportunity Is Nothing) Then
                            Me.UIMathEventLoadedOpportunities = True
                            AddHandler Me.HostApplication.CurrentOpportunityChanged, AddressOf Math_CurrentOpportunityChanged
                        End If
                    End If
            End Select

            xxx()
        Catch ex As System.Exception
            LogError.Write(ex, "MATH:RefreshCurrentView")
        End Try
    End Sub

    Private Sub Math_CurrentContactChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            RemoveHandler Me.HostApplication.ApplicationState.CurrentContact.Fields.FieldChanged, AddressOf Math_FieldChanged
            AddHandler Me.HostApplication.ApplicationState.CurrentContact.Fields.FieldChanged, AddressOf Math_FieldChanged

        Catch ex As System.Exception
            LogError.Write(ex, "MATH:Application_CurrentContactChanged")
        End Try

    End Sub

    Private Sub Math_FieldChanged(ByVal fieldName As String)
        Try
            Select Case HostApplication.CurrentViewName
                Case Durkin.Common.Classes.ACTUIToolkit.ACTViews.ContactDetailViewName
                    ' Your code here!

                Case Durkin.Common.Classes.ACTUIToolkit.ACTViews.CompanyDetailViewName


                Case Durkin.Common.Classes.ACTUIToolkit.ACTViews.GroupDetailViewName


                Case Durkin.Common.Classes.ACTUIToolkit.ACTViews.OpportunityDetailViewName, Durkin.Common.Classes.ACTUIToolkit.ACTViews.OpportunityViewName


            End Select

        Catch ex As System.Exception
            LogError.Write(ex, "MATH:Math_FieldChanged")
        End Try
    End Sub

Hope this helps

-- Jim Durkin

Tuned Listener
Posts: 17
Country: France

Re: Field Changed Event handler don't fire when view change but not contact

It doesn't work ...

I have always the same problem.

 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Field Changed Event handler don't fire when view change but not contact

Can you post your code?