Overblog
Edit post Folge diesem Blog Administration + Create my blog

Do it silently

27. Februar 2009 , Geschrieben von Andreas Weiden Veröffentlicht in #Forms

The task

Another often asked question from the forum

How can i supress that message FRM-40401..... when doing some programmatic COMMIT_FORM ? And its not only the COMMIT_FORM, it could also be EXECUTE_QUERY with the message FMR-40350...

The logic behind

Each message or error forms raises has a message-level assigned (something like a "ranking"). And there is a forms-setting what is the "actual" level the forms-session deals with. This is stored in :SYSTEM.MESSAGE_LEVEL. Now, for every message or error to be shown, forms checks the messages message-level against the "actual" level. The message or error is raised only if the messages message-level is equal or bigger as the system-setting. The actual raising of messages and errors occurs by firing the ON-MESSAGE-triger for messages and ON-ERROR for errors.

An example
  • The user clicks on the save-symbol in the smartbar, there are no changes to save.

  • Forms now would show the "FRM-40401 No changes to save"-message, which has a message-level of 0.

  • Forms checks this message-level (0) against the SYSTEM.MESSAGE_LEVEL (which is by default also 0). Because 0>=0, forms fires the ON-MESSAGE-trigger (if existing) with message_type='FRM' and message_code=40401, or it simple displays the message in the message-bar.

How to influence the behaviour - Permanent solution

If the requirement is to supress a message completely, you have to "overwrite" the message or error-handling by implementing the ON-ERROR or ON-MESSAGE-trigger. To stay with the example, lets say we want to supress the FRM-40401 permanently. So we implement our own ON-MESSAGE-trigger:

BEGIN
  IF     MESSAGE_TYPE='FRM'
     AND MESSAGE_CODE=40401 THEN
    NULL;
  ELSE
    MESSAGE(MESSAGE_TYPE || '-' || MESSAGE_CODE || ': ' || MESSAGE_TEXT);
  END IF;
END;

So we just filter the specific message. Running through the example:

  • The user clicks on the save-symbol in the smartbar, there are no changes to save.

  • Forms now would show the "FRM-40401 No changes to save"-message, which has a message-level of 0.

  • Forms checks this message-level (0) against the SYSTEM.MESSAGE_LEVEL (which is by default also 0). Because 0>=0, forms fires the ON-MESSAGE-trigger with message_type='FRM' and message_code=40401

  • Our ON-MESSAGE-trigger just "consumes" the message and nothing is shown to the user.

How to influence the behaviour - Only for specific situations

The other requirement is to supress some messages only in specific situations, e.g. when doing some automatic COMMIT_FORM. Thats the moment to adjust the SYSTEM.MESSAGE_LEVEL up to a level higher than the message(s) to be supressed, do the action and then readjust SYSTEM.MESSAGE_LEVEL again. This would look like

BEGIN
  :SYSTEM.MESSAGE_LEVEL:=5;
  COMMIT_FORM;
  :SYSTEM.MESSAGE_LEVEL:=0;
END;

Running through the example again:

  • The user clicks on the save-symbol in the smartbar, there are no changes to save.

  • Forms now would show the "FRM-40401 No changes to save"-message, which has a message-level of 0.

  • Forms checks this message-level (0) against the SYSTEM.MESSAGE_LEVEL (which is now 5). Because 0>=5 is not true, forms does nothing more.

Encapsulating the logic

As i'm a fan of encapsulation, i created a procedure for the committing logic and have it in my pll:

PROCEDURE PR_SILENT_COMMIT IS
   nMessageLevel NUMBER:=NAME_IN('SYSTEM.MESSAGE_LEVEL');
BEGIN
   COPY('5', 'SYSTEM.MESSAGE_LEVEL');
   COMMIT_FORM;
   COPY(TO_CHAR(nMessageLevel), 'SYSTEM.MESSAGE_LEVEL');
END;

The same also exists for silent execute-query ....

 

 

Diesen Post teilen
Repost0
Um über die neuesten Artikel informiert zu werden, abonnieren:
Kommentiere diesen Post