Thursday 4 June 2009

How to Debug Ajax and On Demand Processes

I am getting several emails every week regarding one the same issue - Ajax and On Demand Process. In the most of the cases there is a problem with the On Demand Process code. Unfortunatelly Apex is not going to compile your code once you save it. If there is an error in your code the results will not be as expected. On the other side it is quite easy to debug that:

1. Try running your code in SQL Workshop - if your process is supposed to generate an XML file for a select list, you should see a select list if the code is O.K.



2. Use Firefox and download Firebug. Using Firebug you will be able to immediatelly see the results of the On Demand Process you created. Just open the Console and run your process:



3. Be carefull with naming of your On Demand Process - the name of your process in the javascript has to exactly match the name of the process in application processes. Using Firefox and Firebug will help to find that out:



4. Javascript is using htmldb_Get function to call your process the same way you would do that by typing it in the browser address bar - having a blank character there would retreive no results. That means that thhe part of the javascript code


htmldb_Get(null,html_GetElement('pFlowId').value,
'APPLICATION_PROCESS=CASCADING_SELECT_LIST1',0);
get.add('CASCADING_SELECTLIST_ITEM_1',pThis.value);


equals to


f?p=&APP_ID.:0:&SESSION.:APPLICATION_PROCESS=CASCADING_SELECT_LIST1:
NO::CASCADING_SELECTLIST_ITEM_1:30


5. This would also mean that you can test your process using a simple link in your browser:



6. Make sure to name your application and page items correctly in the javascript part of the code. If your misstype a name no explicit error message will be issued. However, using Firefox and Firebug you will see a lot of javascript code in the Console and eventually find an error like displayed in the following screenshot:



7. Finaly, opening the "Post" Tab in Firebug, you will get an overview of your main parameters:



Enjoy debugging your ajax code.

7 comments:

  1. Denes,
    Thanks for the post. It came to my rescue. This just helped me speeding up in trouble-shooting one of the on-demand processes I'm working on.

    Ittichai

    ReplyDelete
  2. Hi Denes,

    I have the same requirement as you have mentioned in the below URL:

    http://htmldb.oracle.com/pls/otn/f?p=31517:239:1716219106753806

    I followed the steps. I changed the Application Process. As you said i tested the following code in SQL Workshop but it failed. The code is:


    DECLARE
    v_desc varchar2(100);
    CURSOR cur_c
    IS
    select description
    from Mtl_Item_Locations mil
    where INVENTORY_ITEM_ID = :apex_application.g_f15();

    BEGIN
    FOR c IN cur_c
    LOOP
    v_desc := c.description;
    END LOOP;

    OWA_UTIL.mime_header ('text/xml', FALSE);
    HTP.p ('Cache-Control: no-cache');
    HTP.p ('Pragma: no-cache');
    OWA_UTIL.http_header_close;
    HTP.prn ('item id="f06_' || apex_application.g_f15() || '">' || v_desc || '');

    END;

    Could you point me out where i am going wrong?


    Thanks
    Rakesh

    ReplyDelete
  3. What you are trying to do doesn't make sense. You need to pass the value of the cell in your tabular form to an application item and then reference the value of it in your application process. You can't reference values from a tabular form (apex_application.g_f15()) in an application process.

    Denes Kubicek

    ReplyDelete
  4. Denes,

    I have created a Master Detail form using the wizard.So i am trying to achieve the functionality in the detail form.

    So i have created 2 pseudo columns in my detail form SQL query - 1 with the name f15 and another with f16. i reference them in the Javascript get.add function...

    Am i doing the right thing?


    Thanks,
    Rakesh

    ReplyDelete
  5. This example

    http://apex.oracle.com/pls/otn/f?p=31517:239

    shows how to parse a tabular cell value to an application process. What you did is not similar to what I show in the code.

    Denes Kubicek

    ReplyDelete
  6. Denes,
    I am going through the same example. I have a LOV and i am calling a onchange on it and passing 2 values as you are doing..

    When you say "Create two application items - TEMPORARY_APPLICATION_ITEM, T_ROWNUM", these 2 items will have no value intially? They would get values in the javascript through the get.add function as shown in the code right?



    Rakesh

    ReplyDelete