Tuesday, August 10, 2010

Stop the online save processing without displaying the error message

Recently during one of my development activity, I came across a requirement in which I needed to stop the save processing at certain condition.


First thing that came to my mind to use exit(1) function but it didn't work as exit(1) takes you out of peoplecode event but it doesn't stop the save processing.

In order to stop the save processing you need to raise an error but whenever you issue a error statement, it comes as a alert box on user window which was not desirable in my case.

After doing some googling I found a way to stop the online save processing without displaying the error message.
Steps:
1. Insert a HTML area on the 0 level of the page.

2. Assign a constant value to this HTML area as mentioned below.
Java Script Code



3. Now raise an error message like in save prechange people code

   Error "$sys$NoEcho: Save Cancelled";
Whenever system finds this magical string "$sys$NoEcho" in error statement, system will stop the save processing without displaying the error.


5 comments:

  1. This is only working in 8.48 and not in 8.52 . Any updates on how to make it work in 8.52 as there is no javascript alert in 8.52

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. There is way to make it work in People Tools 8.51.

    1. Open HTML in Application Designer: PT_AJAX_NET

    2. There is object -> net.msgList;

    It pulls the Messages in GENMSG Tag with below statement.

    net.msgList = xmlDoc.getElementsByTagName("GENMSG");

    Each message is then looped through to with below code

    if (net.msgList)
    {
    for (var i=0; i < net.msgList.length; i++)
    {
    var msg = net.msgList[i].firstChild.data;

    if (!popupObj_%FormName.Initialized)
    popupObj_%FormName.init();
    popupObj_%FormName.addMsg(msg);

    }

    3. Modify the code to prevent message from being displayed which is containing the magic string $sys$NoEcho

    So above code block code to be modified as below,

    if (net.msgList)
    {
    for (var i=0; i < net.msgList.length; i++)
    {
    var msg = net.msgList[i].firstChild.data;
    //% Begin
    if (msg.indexOf("$sys$NoEcho") == -1)
    {
    //% End
    if (!popupObj_%FormName.Initialized)
    popupObj_%FormName.init();
    popupObj_%FormName.addMsg(msg);
    //% Begin
    }
    //% End
    }

    ReplyDelete
  4. Hi,
    I am using PeopleTool 8.51.25.
    and code in above image is not working.
    its still displaying the error message.

    ReplyDelete
  5. Hi, I am using Peopletools 8.49 and the code is displaying the error message.
    Any suggestions?

    ReplyDelete