Friday, May 18, 2018

When Return from DoModal Causes "Page Data is Inconsistent" Error

When you click the OK button on a PeopleSoft modal dialog and the code that it returns to calls the DoSave() or a DoSaveNow() function, you will very likely experience the "Page Data is Inconsistent with Database" error.  But when you click the Cancel button on that same modal dialog, your DoSave() and DoSaveNow() will likely work just fine.  I'll explain why in the article below.




If the secondary page that is popped-up has the "OK & Cancel buttons" box checked, as shown below, your page will include OK and Cancel buttons (by default in the bottom left corner of the pop-up page).   When you click the OK button, even though there is not PeopleCode behind it that you can see in App Designer, it will invoke the command EndModal(1).  Similarly, clicking the cancel button will invoke EndModal(0).

Figure 1.
Alternatively, you can uncheck the "OK & Cancel buttons" box, and manually place button/hyperlink objects on your page in the App Designer canvas. In such case, you'll need to supply the EndModal(1) or EndModal(0)commands in the FieldChange PeopleCode for those buttons' component record.field.

The important difference to understand between EndModal(1) and EndModal(0)is explained in PeopleBooks.  The EndModal return value is:
A number value that determines whether the secondary page data is copied back to the parent page. A positive value runs SaveEdit PeopleCode and copies the data (this is the same as clicking the OK button). A value of zero skips SaveEdit and discards buffer changes made in the secondary page (this is the same as clicking the Cancel button). 
Because of this behavior, if you need to perform some update logic and call DoSave() or DoSaveNow() right after returning from your DoModal call (as shown below) you will not be able to return from your modal dialog window using EndModal(1) 

Figure 2.
Therefore, you will not be able to check the "OK & Cancel buttons" box as shown in Figure 1.  Rather, you'll need to create a record field (such as MY_RECORD_WK.MY_DONE_BTN) and place a button/hyperlink object referring to that record.field on your page.  It's probably a good idea, rather than labeling the button "OK or "Cancel", to label it as "Done".  On the FieldChange event for that button (or that record.field), type in EndModal(0).  That will help you avoid the "Page Data is Inconsistent" error.

No comments: