on 07-04-2006 8:35 AM
Hi everybody,
Does anyone knows if the Add function (like in JournalEntry.Add()) ends a transaction when it fails?
Thanks
Ronen
Hi Ronen.
Yes. A business object manipulation (Add/update...) end a global transaction if it fails (By definition)...
I guess you have some batch-run that you need to run a global transaction around it, but you want to loop through everything in order to give a more detailed error-log (Common problem) - If that the case try this.
1. Begin transaction
2. create a boolean to determine if any errors occured
3. Begin loop
4. Do business object manipulations
5. If business object manipulations fails set the boolean to true (error occured) and begin a new global transaction (This is used cancel futher new business transactions that goes well)
6. After loop, check if boolean have detected any errors during the run. If error, du a global endtransaction and rollback (And show errors), else do a endtransaction and commit...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes... look in step 5 in my previous reply... Here I start a new global transaction after the business object Add method failed (in order to complete the loop to get all errors)... It's a bit complicated to picture in your mind that after a failure you need to start a new transaction, but it works (I normally draw an illustration of the loop to get an overview of it)... I've used it many times, and it works...
Yes it will...
0 - bool errors_on_the_way = false
1 - Start transaction
2 - Add #1 (ok)
3 - Add #2 (ok)
4 - Add #3 (fail (All are rolled back since last start transaction))
5 - Start new transaction as part of #3 fail and remember that an error occured (errors_on_the_way = true)
6 - Add #4 (ok)
7 - Add #5 (ok)
<no more>
if(errors_on_the_way) {
//Rollback transaction (Roll back #4+5 (#1-3 is already rolled back))
}
else {
//Commit transaction (Only in none fails)
}
In this case this will result in no add to the company since #3 failed (And all 5 was tested if they could be added)
Message was edited by: Rasmus Jensen
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.