Community
Showing results for 
Search instead for 
Do you mean 
Reply

*BUMP* FieldChanged Event Not Firing

New Member
Posts: 8
Country: United_Kingdom

*BUMP* FieldChanged Event Not Firing

Hi there,

 

I'm developing a plugin for ACT Premium 2011 and I've run into a problem which doesn't seem to be resolvable.

I've seen a number of other people mention this on the forum but there doesn't seem to be any conclusive solution so I'm hoping someone will be able to assist Smiley Happy

 

My client has created a number of custom fields for their company view along with a number of tabs.

They want me to develop custom functionality whereby if a number of fields on tab A are updated then corresponding fields on tab B should be modified accordingly based on business rules.

 

I've developed the plugin and have it working but only for the first field change. I modify a field on tab A, the FieldChanged event is fired and the corresponding field on tab B is updated as expected. If I subsequently switch back to tab A and modify another linked field then the FieldChanged event is not fired again and so it's not possible to make the necessary modifications.

 

I've tried adding re-adding the event handler again in the CompanyUpdated event which was recommended on one of the posts. This does not work.

The only way it's possible to make this work is to press F5 before modifying the next field or to switch to another company and back again but both of these are unacceptable from a user point of view.

I've tried to mimic this behaviour with different refresh methods after updating the company:

ActApplication.Refresh();

ActApplication.RefreshLoadedViews();

ActApplication.UICompanyManager.RefreshCompanyDetailView();

None of these have the desired effect.

 

Does anyone have any idea how to make this work? It seems like a longstanding problem but it surely cannot be that complex to fix?

 

Related info:

Sage ACT! Premium 2011 Version 13.0.401.0, Hot Fix 2

Windows 7 64Bit - SP1

 

I'd really appreciate any assistance anyone can give.

 

James

 

P.S. I can post my code if it helps but I've left it out now for brevity.

 

 

Employee
Posts: 1,163
Country: USA

Re: *BUMP* FieldChanged Event Not Firing

Hello James,

 

I tried to recreate this and was unsuccessful in doing so. I used existing tabs and standard fields, but for the purposes of this it shouldn't matter. I set my code to watch for changes to TBL_CONTACT.HOME_POSTALCODE and if changes were made it'd update the USER1 field. Here is the relevant portions of the code I was using:

 

void AfterLogon(object sender, EventArgs e)
{
ActApp.CurrentContactChanged += new EventHandler(ActApp_CurrentContactChanged);
}

void ActApp_CurrentContactChanged(object sender, EventArgs e)
{
ActApp.ApplicationState.CurrentContact.Fields.FieldChanged
+= new MutableEntity.FieldCollection.FieldChangedHandler(Fields_FieldChanged);
}

void Fields_FieldChanged(string fieldName)
{
if (fieldName == "TBL_CONTACT.HOME_POSTALCODE")
{
SetContactFieldValue();
}

private void SetContactFieldValue()
{
Contact myContact = ActApp.ApplicationState.CurrentContact;
ContactFieldDescriptor userField = ActApp.ActFramework.Contacts.GetContactFieldDescriptor("TBL_CONTACT.USER1", true);
userField.SetValue(myContact, "UPDATED!!");
myContact.Update();
}

 

Since I'm not registering for the event until ContactChanged, it doesn't work for the first contact. If you're doing something similar/identical to what I'm doing and it's simply not working for either companies or custom fields/tabs, let me know and I'll test with that as well. 

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 8
Country: United_Kingdom

Re: *BUMP* FieldChanged Event Not Firing

Hi Matthew,

 

Many thanks for your response. Much appreciated.

 

Ok, so after further experimentation I've discovered that the problem seems to be related to the modifying related Yes/No fields.

If the following occurs:

1. User sets the value of field A

2. FieldChanged event fired for field A

3. Programmatically set the value for related field B

4. Call CurrentCompany.Update() within the FieldChanged event handler for field A

5. FieldChangedEvent is received for field B as expected

No further field changed events will be received for that company.

 

Below is some code which illustrates the problem. If you modify the postal code of the company then a custom yes/no field is updated. If you modify the address line2 then address line3 is updated with the timestamp. You can modify the address line 2 field as many times as you like without any problem however once you modify the postcode and the custom yes/no field is set you will not receive any more events.

 

Any ideas about this?

 

Best Regards,

James

 

=======

 

 

 

        void After_Logon(object sender, EventArgs e)
        {
            application.CurrentCompanyChanged += new EventHandler(ActApp_CurrentCompanyChanged);
            application.BeforeLogoff += new EventHandler(ActApp_BeforeLogoff);
        }

        void ActApp_BeforeLogoff(object sender, EventArgs e)
        {
            application.CurrentCompanyChanged -= new EventHandler(ActApp_CurrentCompanyChanged);
        }


        void AfterLogon(object sender, EventArgs e)
        {
            application.CurrentCompanyChanged += new EventHandler(ActApp_CurrentCompanyChanged);
        }

        void ActApp_CurrentCompanyChanged(object sender, EventArgs e)
        {
            application.ApplicationState.CurrentCompany.Fields.FieldChanged
            += new MutableEntity.FieldCollection.FieldChangedHandler(Fields_FieldChanged);
        }

        void Fields_FieldChanged(string fieldName)
        {
            MessageBox.Show(fieldName + " modified");
            if (fieldName == "TBL_COMPANY.BUSINESS_POSTALCODE")
            {

                SetYesNoField();
            }
            else if (fieldName == "TBL_COMPANY.BUSINESS_LINE2")
            {
                SetTextField();
            }

        }

        private void SetYesNoField()
        {
            Company myCompany = application.ApplicationState.CurrentCompany;
            CompanyFieldDescriptor businessLine3Field = application.ActFramework.Companies.GetCompanyFieldDescriptor("TBL_COMPANY.CUST_CHECKBOX_1", true);
            businessLine3Field.SetValue(myCompany, true);
            myCompany.Update(true);
        }

        private void SetTextField()
        {
            Company myCompany = application.ApplicationState.CurrentCompany;
            CompanyFieldDescriptor businessLine3Field = application.ActFramework.Companies.GetCompanyFieldDescriptor("TBL_COMPANY.BUSINESS_LINE3", true);
            businessLine3Field.SetValue(myCompany, "Updated "+System.DateTime.Now.ToLongTimeString());
            myCompany.Update(true);
        }

 

Employee
Posts: 1,163
Country: USA

Re: *BUMP* FieldChanged Event Not Firing

Glad to help James.

 

Unfortunately I'm still not getting the same results. I followed the steps that you provided and I remain signed up for the FieldChanged event for the current company regardless of what field type is modified. I don't really see any significant difference in the code that we're using, except I don't pass any parameters in my Update() method, you could try changing that but I'd be surprised if that's the issue. 

 

Since I'm now leaning away from it being a coding issue, what version are you using? Another thing I want to be sure of, the other field should be modified not immediatly after we make the changes to the field, but once we've moved out of it or taken some other action that'd commit the changes to the database. So, stepwise:

 

1. User changes value of field A

2. Some refresh action occurs whether it's moving out of the field or manually hitting F5

3. The value of field B is then modified

 

I modified the code slightly to use companies and created a custom YesNo field so I'll include it below.

 

void Fields_FieldChanged(string fieldName)
{
if (fieldName == "TBL_COMPANY.BUSINESS_STATE")
{
SetCompanyFieldValue();
}
if (fieldName == "TBL_COMPANY.NAME")
{
SetYesNoFieldOnFieldChange();
}
}

 

private void SetYesNoFieldOnFieldChange()
{
Company myComp = ActApp.ApplicationState.CurrentCompany;
CompanyFieldDescriptor YesNoField = ActApp.ActFramework.Companies.GetCompanyFieldDescriptor("TBL_COMPANY.CUST_YesOrNo_094039577");
YesNoField.SetValue(myComp, true);
ActApp.ApplicationState.CurrentCompany.Update();
}

 

private void SetCompanyFieldValue()
{
Company myComp = ActApp.ApplicationState.CurrentCompany;
DBFieldDescriptor CompNameField = ActApp.ActFramework.Companies.GetCompanyFieldDescriptor("TBL_COMPANY.BILLING_LINE1");
CompNameField.SetValue(myComp, "Test!!");
ActApp.ApplicationState.CurrentCompany.Update();
}

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 8
Country: United_Kingdom

Re: *BUMP* FieldChanged Event Not Firing

 

Hi Matthew,

 

The version number is:

Sage ACT! Premium 2011 Version 13.0.401.0, Hot Fix 2

 

To be clear, the sequence of events are:

1. Modify field A value

2. Move focus away from field A

3. FieldChanged event received for field A

4. Programmatically modify value of related field B

5. FieldChanged event received for field B

 

Something to add is that yes/no fields seem to behave differently. If a user modifies a yes/no field on a custom layout tab and then moves focus to another control the FieldChanged event is not fired as would happen with a text based field.

The FieldChanged event does not fire for these fields until the user navigates to a different company.

 

Note: I specified the Update(true) method because when you change some linked fields they don't ask if you want to perform cascading updates until you navigate away from the company. I thought that perhaps this was causing a problem with the event loop so eliminated the confirmation dialogue by adding the flag.

 

I can send you my plugin code to ensure I'm not doing anything stupid. Is there an email address or something I can use for this purpose?

 

Best Regards,

James

 

Employee
Posts: 1,163
Country: USA

Re: *BUMP* FieldChanged Event Not Firing

I'm working in 2012 currently and the field changed event for YesNo fields is firing as soon as I modify it. I'll test this in 2011 and let you know my results.

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 8
Country: United_Kingdom

Re: *BUMP* FieldChanged Event Not Firing

Hi Matthew,

 

Ok, that's great. Once again, thanks for your help.

 

James

New Member
Posts: 8
Country: United_Kingdom

Re: *BUMP* FieldChanged Event Not Firing

Just to let you know, I updated my version of ACT to 13.1.111.0, Hot Fix 6 in case there were any changes included that fixed the problem I'm seeing but unfortunately that hasn't helped.

 

Best Regards,

James

Employee
Posts: 1,163
Country: USA

Re: *BUMP* FieldChanged Event Not Firing

Tested in both 2011 and 2013 and it's still working for me. When you set your debug breakpoint at the FieldChanged event, does it cease to hit that event after modifying a YesNo field? 

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 8
Country: United_Kingdom

Re: *BUMP* FieldChanged Event Not Firing

Hi Matthew,

 

That's correct.

If I call company.update() after modifying a yes/no field programmatically then I don't receive any more fieldchanged events for that company until either I move from that company to another and back again or I press F5.

 

Not really sure why it's working for you and not me. Is there any other information I can give you that might help?

 

James