Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Tuesday, November 26, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - SalesLogix Web Platform & Application Architect
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Web Platform & Application Architect | New ThreadView:  Search:  
 Author  Thread: Updating related entities from property change events.
Nicolas Galler
Posts: 93
 
Updating related entities from property change events.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Nov 07 7:00 PM
I need a bit of help getting the property changed event working.

Here is the scenario (simplified):
Whenever the contact type is modified, all contacts under the same account need to be updated to the same type.

I have this code in a property changed event:

public static void OnBeforeTypeChanged(IContact contact, ExtendedPropertyChangedEventArgs args)
{
foreach(IContact c in contact.Account.Contacts){
if(c.Id != contact.Id){
c.Type = (String) args.NewValue;
}
}

However I get this error when updating the type:
Already executing the OnBefore / OnAfter business rule for the IContact.Type property.

I tried a few different combinations but can't get it to work.
I tried adding a call to ((EntityBase)c).SuspendChildNotification() or ((EntityBase)c).SuspendNotification() but still got the error.
If I put the same code in the "AfterPropertyChanged" handler I don't get the error but the changes don't get saved.
I tried adding some explicit Save() calls at that point but that locked up asp.net.

It seems like a pretty common scenario. Also seems like it should be easy with the ORM and those events.

I ran out of time so I ended up doing it via a round about way but I still wish I got these events working.

Any idea?

Thanks
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Updating related entities from property change events.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Nov 07 1:10 PM
The "Id" property is an object, not a string. So your check to compare if the loop contact is the same as the current contact isn't working and you're trying to update the same contact again.

Change the if statement to this and it should work:

public static void OnBeforeTypeChanged(IContact contact, ExtendedPropertyChangedEventArgs args)
{
foreach(IContact c in contact.Account.Contacts){
if(c.Id.ToString() != contact.Id.ToString()){
c.Type = (String) args.NewValue;
}
}
}


-Ryan
[Reply][Quote]
Nicolas Galler
Posts: 93
 
Re: Updating related entities from property change events.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Nov 07 8:44 PM
Well, the code does work. It should be fine to do comparison by reference in this case since the objects are all loaded from NHibernate (in the actual code I have a log statement that shows only the other contacts are getting updated). I have it called from the save button now instead of in the event handler which in this particular instance probably makes more sense anyway.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 11/26/2024 2:32:51 PM