This discussion is archived
10 Replies Latest reply: Nov 25, 2012 4:17 AM by Gaurav Nagpal RSS

apex_application.g_print_success_message

894843 Newbie
Currently Being Moderated
Hi all..

Please help me with the following issue.
I have a PL/SQL process on a page (after submit process).

I am using

""apex_application.g_print_success_message"" variable to show any error message.
Ex: apex_application.g_print_success_message := 'Process failed at this step';
It seems "apex_application.g_print_success_message" variable is for success messages .
I want my "'error message"" to show in the same way as my ""validation error messages"" , as they are really ""error message"".

I also tried to use ""apex_application.g_notification"" but it didn't worked. My message is not showing up.


I tried to use the following code, but it seems it counts the error count
only for the ""validation error messages"" , not the error message that i set in the process.
{code}
if nvl(apex_application.g_inline_validation_error_cnt,0) = 0 then
<real code here>
end if;
{code}

Thanks
  • 1. Re: apex_application.g_print_success_message
    717965 Newbie
    Currently Being Moderated
    Don't be misled by the name. "apex_application.g_print_success_message" is a function that outputs messages in Apex. The message it outputs can be a failure or a success message.

    I'm going to assume what you wanted was to capture the amount of errors happened in your process and return it as an out msg. How you capture it is up to you. Below is one example of many ways you can trap errors in the body of a process to return an error or success message.

    In this example if the loop hits 5 (which it will) it will return an error and display the "supposed" amount of errors. regardless whether if if condition is met or not. The bottom line is that "apex_application.g_print_success_message" is just going to display the out put.

    I hope this helps.

    declare
    v_out_msg varchar2(20);
    function test_func(ipv_text number)
    return varchar2
    as
    n_cnt number := 0;
    retval varchar2(20) := 'SUCCESS';
    begin
    for i in 1..6
    loop
    n_cnt := n_cnt +1;
    if n_cnt = 5 then
    retval := 'ERROR';
    end if;
    end loop;
    return retval ||'('||n_cnt||')';
    end;
    begin
    v_out_msg := test_func(1);
    -- dbms_output.put_line(v_out_msg);
    apex_application.g_print_success_message(v_out_msg);
    end;
    /

    Edited by: user1818135 on Jan 4, 2012 2:17 PM
  • 2. Re: apex_application.g_print_success_message
    894843 Newbie
    Currently Being Moderated
    Hi ..

    Sorry to say this..
    I think you might not understood my problem.

    I am using the global variable "'apex_application.g_print_success_message"", for my ""error messages in my PL/SQL process".

    I dont want to do that, if i set "'apex_application.g_print_success_message"" the message will display in ""SUCCESS MESSAGE TEMPLATE"".
    which is different from ""ERROR MESSAGE TEMPLATE".

    I want to look those message like ""error messages"

    Thanks
  • 3. Re: apex_application.g_print_success_message
    jariola Guru
    Currently Being Moderated
    Hi,

    Try global variable apex_application.g_notification instead of apex_application.g_print_success_message



    Regards,
    Jari

    http://dbswh.webhop.net/dbswh/f?p=BLOG:HOME:0
  • 4. Re: apex_application.g_print_success_message
    Luis Cabral Pro
    Currently Being Moderated
    Hi,

    What Apex version are you using? Before 4.1, I think it is not possible to do what you want. It seems that error messages are generated only during the validation step. After the validation step is finished, there is nothing you can do to problematically display a custom error message (as far as I know, and I tried lots...)

    I suggest you use a function returning varchar2, and put it in a return-error-message validation (instead of a page process). The validation should be the last one, probably with the condition "no previous errors found."

    I hope this makes sense and helps somehow.

    Luis
  • 5. Re: apex_application.g_print_success_message
    894843 Newbie
    Currently Being Moderated
    Hi luis..

    Sorry for the very late reply.

    we are on APEX 4.1 . Is there any solution in APEX 4.1?
    I suggest you use a function returning varchar2, and put it in a return-error-message validation (instead of a page process). The validation should be the last one, probably with the condition "no previous errors found."
    I cannot do that luis. Because i am calling a database procedure which return different "status", and depends on the status, i need to assign the ""error"" or ""success" message.

    I am able to see the message, but i need error messages go to ""NOTIFICATION TEMPLATE"" and success messages go to ""SUCCESS TEMPLATE""

    Please let me know if you can suggest me something
  • 6. Re: apex_application.g_print_success_message
    Luis Cabral Pro
    Currently Being Moderated
    In 4.1 you have some more control on how error messages are displayed, but even so I don't think you can do what you want (to generate a success or error message from the same process.) I haven't worked with 4.1 so I cannot sure...

    Still insisting with my proposed validation-based solution, why don't you return an error message only if there is an error? Then the error message will be displayed as expected.

    If there is no error, you assign the success message to apex_application.g_print_success_message and return NULL. The success message will then be displayed as expected too.

    Another (ugly) option is to surround the message with some HTML to make it "look" like the error message template and call the procedure from a page process as it is being done now.

    Luis
  • 7. apex_application.g_print_success_message
    894843 Newbie
    Currently Being Moderated
    Hi Luis or anyone....

    Luis..Thanks for your replies regarding this issue.
    As i said in one of my previous step, I don't have option to move my code to ""validations""

    This is the overview of what my process do.
    begin
    --
    -- do some steps
    --
    
    call_database_procudre(return_code);
    
    if return_code = 'OK' then
     
    apex_application.g_print_success_message := 'Success mesasge';
    
    --
    -- do other steps
    --
    
    else
    
    apex_application.g_print_success_message := 'Fail Message'; """I want this one to show like ""error"" """
    
    -- How can i style it to show like in ""error message""" template.
    
    --
    -- do other steps
    --
    
    end if;
    {code}
    
    
    Anyone..PLease help me to solve this issue.
    
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  • 8. Re: apex_application.g_print_success_message
    Gaurav Nagpal Newbie
    Currently Being Moderated
    Hello Kumar,

    I am also facing the same problem.you got any solution? Thanks.Gaurav Nagpal
  • 9. Re: apex_application.g_print_success_message
    Luis Cabral Pro
    Currently Being Moderated
    Gaurav Nagpal wrote:
    I am also facing the same problem.you got any solution? Thanks.Gaurav Nagpal
    Uh, you are reviving an old thread, the forum police will be soon after you :)

    In fact recently I had the same problem and the solution I used was to surround the message with an span tag with the required class to "mimic" the notification template, e.g.:
    apex_application.g_print_success_message := '<span class="notification">Process failed at this step</span>';
    (obviously you should use a custom function which accepts a message and a flag to indicate whether it is an error or not instead of polluting your code with HTML tags everywhere...)

    I find this ugly but it seems to be the only way with 4.0...

    Cheers
    Luis
  • 10. Re: apex_application.g_print_success_message
    Gaurav Nagpal Newbie
    Currently Being Moderated
    I handled the issue in the validation of the page...Instead of displaying the success message /error message in the process using Raise application Error..Its working as expected.

    Thank you.

    Gaurav Nagpal.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points