Community
Showing results for 
Search instead for 
Do you mean 
Reply

FieldChanged not firing the first time

Accepted Solution Solved
Highlighted
Copper Contributor
Posts: 13
Country: USA
Accepted Solution

FieldChanged not firing the first time

What I am trying to accomplish: watch for if a contact field is changed via an Act! Premium plugin, and if so, send the data off to another application.

 

My approach: wait for the contact view to be used. Listen for the Changed and Changing events. When ContactChanged, start listening for FieldChanged on the CurrentContact. When ContactChanging stop listenign for FieldChanged. I also manually call ContactChanged when the view is first loaded to ensure that FieldChanged is attached to.

 

The problem: FieldChange never fires after the Contact view is loaded but before moving to another contact. Ie., if I switch to the contacts view, and change a field, no FieldChanged. If I switch to another contact and change a field, FIeldChanged fires just fine.

 

Skeleton Code:

 

 

class ActPlugin : IPlugin
{
    protected void Application_AfterLogon(object sender, EventArgs e)
    {
        // attach to application events
        application.CurrentViewChanged += Application_CurrentViewChanged;
    }

    protected void Application_CurrentContactChanged(object sender, EventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("Application_CurrentContactChanged");

        Contact contact = application.ApplicationState.CurrentContact;
        System.Diagnostics.Debug.WriteLine("contact: " + contact.FullName);

        // attach to contact events
        contact.Fields.FieldChanged += FieldCollection_FieldChanged;
    }

    protected void Application_CurrentContactChanging(object sender, EventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("Application_CurrentContactChanging");
        
        // dettach from contact events
        contact.Fields.FieldChanged -= FieldCollection_FieldChanged;
    }

    protected 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;

            // trigger CurrentContactChanged for the first contact
            Application_CurrentContactChanged(sender, e);
        }
        else
        {
            // detatch events
            Contact contact = application.ApplicationState.CurrentContact;

            if (contact != null)
            {
                // dettach from contact evetns
                application.CurrentContactChanged -= Application_CurrentContactChanged;
                application.CurrentContactChanging -= Application_CurrentContactChanging;
            }
        }
    }

    protected void FieldCollection_FieldChanged(string fieldName)
    {
        System.Diagnostics.Debug.WriteLine("FieldCollection_FieldChanged: " + fieldName);
    }
}

 

 

 


Accepted Solutions
Highlighted
Solution
Accepted by topic author apemberton
‎09-25-2015 03:20 AM
Employee
Posts: 1,163
Country: USA

Re: FieldChanged not firing the first time

I'm sure your code is fine, this is an issue that's been around for a while. What most folks have done to work around this is to force a refresh once the view is loaded for the first time.

Matthew Wood
Act! SDK Support
Community Moderator

View solution in original post


All Replies
Highlighted
Solution
Accepted by topic author apemberton
‎09-25-2015 03:20 AM
Employee
Posts: 1,163
Country: USA

Re: FieldChanged not firing the first time

I'm sure your code is fine, this is an issue that's been around for a while. What most folks have done to work around this is to force a refresh once the view is loaded for the first time.

Matthew Wood
Act! SDK Support
Community Moderator
Highlighted
Copper Super Contributor
Posts: 112
Country: Australia

Re: FieldChanged not firing the first time

Matt

 

Do you know if this long standing "problem" has been addressed and corrected in the new 2011??

 

Greg

Highlighted
Employee
Posts: 1,163
Country: USA

Re: FieldChanged not firing the first time

[ Edited ]

It has not, the Field Changed event does not fire until after the first refresh.

Matthew Wood
Act! SDK Support
Community Moderator
Highlighted
Copper Super Contributor
Posts: 71
Country: Canada

Re: FieldChanged not firing the first time

Matt,

 

I have a refresh set on the actapp.open event, which works and refreshes ACT! so a field event will trigger, however it seems that the actapp.open event only runs for me when running act from the actsage.exe or shortcut, if I open ACT! from a .pad file the open event does not run, is there anyway to fix this, I was talking with greg (previous post before yours) about this and he is not sure why it isnt working for me and I have tried many things, alot of people open databases through the .pad so I am hoping you might know why this event does not trigger in that situation.

 

Thanks.

Highlighted
Employee
Posts: 1,163
Country: USA

Re: FieldChanged not firing the first time

I think the Durkin Auto refresh utility is free and should work in all circumstances.

 

Aside from that I think ViewLoaded may work, but you'd have to set a flag so it didn't occur every time a view was loaded.

Matthew Wood
Act! SDK Support
Community Moderator
Highlighted
Bronze Super Contributor
Posts: 1,284
Country: USA

Re: FieldChanged not firing the first time

Yes the Autorefresh plug-in is free and it includes all the source code which I attached here.

Autorefresh a simple plug-in framework written in VB in Studio 2008.  Not much to look at but it gives anybody the basic understanding to write a custom plug-in for ACT!.


If you want a more detailed examples you can download our FREE Durkin Toolkit SDK.  This ACT framework project starter kit allows you to create custom ACT! plug-ins from project template in VS 2005 or 2008 for both VB and C#. It is very robust since it covers all the functionality in our Durkin Toolkit libraries for custom tables and custom view. It allows you to do things like:
1) Attach buttons to any toolbar included custom table views usrViewSubEntity.AddToolBarItem(Key, "MyButton", MyIcon)
2) Monitor ToolkitEvent_EventAfterNew, ToolkitEvent_EventBeforeEdit events or any custom sub entity
3) Monitor ToolkitEvent_CurrentFieldValidating for any custom table fields ( Great place to hook in math functions )
4) Monitor ToolkitEvent_CustomViewLoaded  so you know when a user changed to a custom table view.  

To download and install the full Toolkit SDK you can use this link: http://durkincomputing.com/ACTAddonsDownloads/DurkinSDKInstaller.exe 

Hope this helps

-- Jim Durkin