Possible bug or timing issue with triggers

Posted by jsniemi79 on 30-Mar-2015 12:51

I am having an issue with some related records not getting created correctly.  I'm not sure if it is purely a timing issue with the objects and triggers I have set up or a possible bug.

I have an object called Opportunities.  When I create a new opportunity, I have a related object called opportunity details that I have as an editable grid on my new opportunity page. 

I have script running on load of the new page to read another object to determine what details I want in the grid, so it is prepopulated with a few values when the user lands on the page.

After filling out all the required data, I click save.  At that point, it should create my opportunity detail records. This appears to work correctly.  Upon create of the details, I have an object script trigger that runs to update a field value, then convert the opportunity detail into a child opportunity and then delete the opportunity detail record.  

The end result should be my original opportunity, with related child opportunities based on the details entered in the editable grid.  

I'm doing it this way because I can't have an editable grid of child opportunities on the new page of an opportunity.

The Issue :

The issue I am seeing is the relationship to the parent opportunity isn't always getting created correctly for the first record in the grid.  This is resulting in all the objects being created, but not all of them being related.

In this example, I have three categories on the main opportunity.

When I hit submit, the first category (opportunity detail) is created as an opportunity, but it didn't end up being related to the main opportunity.  As you can see, I have only two of the children opportunities created correctly.

If I go to all opportunities, I can see the first category did get created, but not related to the parent.

The other thing about this is id doesn't happen every time.  I can't figure out exactly what causes it to work sometimes, but not others, which is why I thought it might be a timing issue with the triggers.

Any help would be greatly appreciated.  If you need access to the system, just include your email address and I will get you setup.

Thanks

All Replies

Posted by pvorobie on 30-Mar-2015 13:10

If you're performing processing of data from Grid Control, please make sure your trigger has "On Finalize" timing, not "On After Update".

Posted by jsniemi79 on 30-Mar-2015 13:54

I've added the "On Finalize" timing as it was previously just Create.  I'm not sure that would explain why this only happens sometimes and only to the first record in the grid control though.

Posted by Godfrey Sorita on 30-Mar-2015 14:27
Use Trigger Debugger (http://documentation.progress.com/output/Rollbase/index.html#page/rb/debugging-complex-triggers.html) to check which triggers have run during a transaction. You should also be able to trace the values of tokens and variables using rbv_api.print() API during an actual transaction. Below is a sample result of a trigger which runs "On Finalize":

Running SELECTED on Project 4 (ID=10232)
Checking trigger: test (ID=21941)
Running test on Project: Project 4 (ID=10232)
DEBUGGING INFO:
Finalize!
===============================
Finished SELECTED on Project 4 (ID=10232)
Posted by jsniemi79 on 02-Apr-2015 11:32

I have verified that the triggers are firing as I would expect.  I don't know where to go next on this to get it figured out.  I have a parent record that is running a trigger to create related records.  It will successfully create all the necessary records, but randomly, the first record in the grid control is created without mapping the parent record.  Then, the remaining records are successfully related.  

Would you like access to the environment to take a look?

Posted by Godfrey Sorita on 03-Apr-2015 10:37
Please check for update APIs on the parent object which updates the child records. When using setFieldValue outside a related loop to update a child record, it only updates the first record on the grid control. This might be a possible culprit for this issue.

I recommend logging a support case for this question/problem so a Progress TSE may assist you debugging and pointing the cause of the error.
This thread is closed