Jump to content

Validating parent record against related records before commit


oakbridge
 Share

This topic is 2548 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I'm working on a invoice payment function. There are invoices that have been issued, and when a payment is received at head office it can be for the full amount for a single invoice, a partial amount on a single invoice, the full amounts for multiple invoices, partial amounts for multiple invoices. 

 

I've got a Payment Header record that has a field for the amount of the payment. The user records it as one of the first steps.

 

I've got 1 to many Payment detail records that have fields for the related invoice that they payment is for, and the amount that is being applied against that invoice. 

 

I want to verify that the total that has been applied to each invoice is equal to the amount of the payment. For example if the payment was for $100, then the sum of the 1 to many detail lines should also be $100. 

 

However I want to do this BEFORE I commit any records. I'm trying to follow the 'transaction' approach. I'm also creating sync records for mobile devices so the commit and transaction approach is important to avoid extra or inaccurate sync log records. I also want this to work for both new payment records and editing existing payment records (until we lock the payment record). 

 

I started by just comparing the amount field (payment_header_amount) against Sum (payment_detail_amount) of the related records. Unfortunately when I look at the Data Viewer, I get different behaviours than what I would expect. (i.e. Data Viewer shows one behaviour on New records and another behaviour on Edited records).

 

I've also tried using script triggers to store the data to global variables from both the header payment amount field and the amount field from the payment detail amount fields but that only works when I specifically change a value in one of them.

 

Anyone have any suggestions? 

Link to comment
Share on other sites

Unfortunately when I look at the Data Viewer, I get different behaviours than what I would expect. (i.e. Data Viewer shows one behaviour on New records and another behaviour on Edited records).

 

 Hm... I tried to reproduce your problem and I found that having the Data Viewer open and monitoring the values interfered with the validation - i.e. I got a validation error when I shouldn't have. Without it, it worked as expected, on both new and edited records (at least I haven't been able to create a discrepancy).

Link to comment
Share on other sites

This topic is 2548 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.