If you’re a PeopleSoft programmer, the Error() function is probably one of the first function you learned in PeopleCode. Raising an error — via the Error or MessageBox functions — is an indispensable operation, and serves multiple purposes throughout the component processor flow. Aside from displaying a message to the user, issuing an error has an accompanying effect which depends on which PeopleCode event it occurs. In FieldEdit, it highlights the affected field and stops further processing; in SaveEdit, it is used to abort save processing (SavePreChange–Workflow–SavePostChange); in RowDelete, it is used to cancel the user delete action.

However, you might come across a situation where you want the effect associated with an error, but displaying a message is not desired (as this chap experienced the need to abort save processing without displaying a message).

The user with the problem did not explain his specific situation. Pondering over this, I think a situation where I would find this necessary is when the requirement calls for displaying a modal page when user clicks on save or deletes a row. The modal page might contain data populated to a grid or other complex information that user needs to review in order to decide whether to proceed with the save or delete. The modal page would contain an Ok and Cancel button; when user clicks Cancel, this should abort the save/delete processing. Because of the complex nature of the information being displayed, issuing a warning is out of the question. Following is how the PeopleCode would look like:


[SaveEdit or RowDelete]
If DoModal(Page.REVIEW_INFO, "Confirm Operation", -1, -1) = 0 Then
   Error "Save/delete canceled.";
End-If;

Now for the user, when he clicks on the Save/Delete button, a fancy page will be presented to him for review. When he clicks on Ok, then the operation is processed. However, when he clicks Cancel, he will receive another message informing him that the operation is canceled — which is pretty much an undesired effect which will likely be frowned upon by the user.

Now, in PIA the error messages are displayed to the user via javascript alert commands appended to the body’s onload handler. By inserting a snippet of javascript to the page via an HTML area, we should be able to override the behavior of the alert function before the messages are actually displayed. The following script checks for a distinct string on message being displayed — in (dis)honor of Sony’s notorious rootkit, LOL — we could assign the string $sys$NoEcho:


<script type="text/javascript">
var oldalert = window.alert;
window.alert = function() {
  var param = arguments[0];
  if (param.indexOf("$sys$NoEcho") == -1) oldalert(param);
}
</script>

After this script is evaluated, the alert function now checks any messages passed to it: if it contains the magic string $sys$NoEcho it will not be displayed. Important note: Make sure to place the HTML area on level 0 of the primary page.

Now the PeopleCode should be modified to include the magic string in the message:


If DoModal(Page.REVIEW_INFO, "Confirm Operation", -1, -1) = 0 Then
   Error "$sys$NoEcho: Save/delete canceled.";
End-If;