07/01/2011

Debugging the Save Warning

While developing pages and components, I'll sometimes get a Save Warning message, i.e. "You have unsaved data on this page. Click OK to go back and save, or Cancel to continue." when I try to leave a component with out having made any changes. This is often caused by PeopleCode updating the value of a field (often hidden) on your page. A quick way to figure out what is the offending field is to use JavaScript debugging. I often develop in FireFox and use the FireBug add-on. (Google Chrome and IE8 have their built-in debuggers.) After turning on your JavaScript debugger, go to the offending page and choose PT_SAVEWARNING JavaScript library. Find the checkFormChanged function and place breakpoints on both of the return true statements in this code block. (This is lines 181 and 184 in PeopleTools 8.50.)

for (var j = 0; j < form.length; ++j)

{
bIsChanged = isChanged(form.elements[j], objFrame);
if (bIsChanged && form.ICSaveWarningFilter) {

if (form.ICSaveWarningFilter.value != "1")
return true;
}

else if (bIsChanged)
return true;
}


Next add a new watch expression in your debugger:

form.elements[j].id


Back in your browser window, do whatever you were doing to trigger the Save Warning message. This time the debugger should stop though and you can inspect your watch expression to see what Form element ID is the one that has changed. This normally matches the RECNAME_FIELDNAME of your field. You can then debug backwards from there in PeopleCode to find the code that is updating this field.

3 comments:

  1. Neil

    I'm trying to track down a save warning problem in PT8.49. Before the code section you quote there is code that checks if form.ICChanged.value was set by the server. This is what is causing my warning (code below).

    Do you have any words of wisdom on tracking down why this is being set by the server? This happens after fieldchange peoplecode that calls doSaveNow(). We've traced the peoplecode and nothing that should trigger the savewarning is changed after the doSaveNow().

    <input type='hidden' name='ICSaveWarningFilter' value='0' />
    <input type='hidden' name='ICChanged' value='1' />
    ....

    function checkFormChanged(form, objFrame)

    {

    if (!form.ICChanged)

    return null;

    if (form.ICChanged.value == "-1")

    return false;

    if (form.ICChanged.value == "1" && form.ICSaveWarningFilter) {

    if (form.ICSaveWarningFilter.value != "1")

    return true;

    } ...

    ReplyDelete
  2. As is often the case, not long after I made my last comment, I discovered a PeopleCode function that disables the SaveWarning.

    SetSaveWarningFilter( True);

    True disables the SaveWarning and False enables it.

    ReplyDelete
  3. Hi Dan, I wasn't aware of the SetSaveWarningFilter built-in PeopleCode function either. I just did a search for the function name on Oracle's on-line version of PeopleBooks and no search results were returned. Thanks for sharing.

    Neil

    ReplyDelete