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.