Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Sunday, June 29, 2025 
 
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: Have an entity with a collection of child entities. Need a DB field that summarizes data from that collection. How to have it in sync?
NixDev
Posts: 98
 
Have an entity with a collection of child entities. Need a DB field that summarizes data from that collection. How to have it in sync?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Oct 10 11:55 AM
Ok, here's the deal.

I have an entity (lets call it invoice) which has a collection of child entities (lets call it invoiceLines). Each invoiceLine has an amount field. I need a db field (a real db field, not calculated one) that summarizes the amount of the invoiceLines at the invoice level. It should stay in sync, so when you add, delete or update an invoiceLine, that amount must be updated. Makes sense?

My approach has been to create a BR on the invoice entity to update that sum:

public static void RecalculateTotalAmount( IInvoice invoice)
{
double? sum = 0;

foreach(IInvoiceLine line in invoice.InvoiceLines){
sum += line.Amount;
}

invoice.TotalAmount = sum;
}

And call that BR on OnAfterInsert, OnAfterDelete and OnAfterUpdate events at the invoiceLine level. The events at the invoiceLine level look something like:

public static void OnAfterUpdateStep( IInvoiceLine invoiceline)
{
invoiceLine.Invoice.RecalculateTotalAmount(); //make the parent invoice recalculate its total amount
invoiceLine.Invoice.Save(); // save the parent invoice
}

It seems to be working all right, but i'm not sure if this is the correct approach to do something like this. I'm also having a problem where I'm inserting a new invoice and start adding new invoiceLines and need to delete one of them. The afterDelete event is triggered, the total amount is recalculated, and the parent invoice is saved (due to the "Save()" at the end of the onAfterDelete) which is wrong. So, i need some way to tell if we are deleting an invoiceLine of an invoice that has not been persisted at all. Makes sense?

I'd like to hear what the more senior people here can comment on this...
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: Have an entity with a collection of child entities. Need a DB field that summarizes data from that collection. How to have it in sync?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Oct 10 2:48 PM
If you were to add a simple SQL view to the db it would do all of the work for you - no need for business rules et al. Why can the field not be calculated? Must you be able to write to this field?
[Reply][Quote]
NixDev
Posts: 98
 
Re: Have an entity with a collection of child entities. Need a DB field that summarizes data from that collection. How to have it in sync?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Oct 10 4:13 PM
The client has specifically asked for a "real" field on the DB, what can I tell you...
[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 © 2025 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): 6/29/2025 9:09:56 AM