Forum Stats

  • 3,826,042 Users
  • 2,260,590 Discussions
  • 7,896,773 Comments

Discussions

Interactive Grid

Nithyaa
Nithyaa Member Posts: 10 Green Ribbon

Hello, I have a interactive grid. If no rows selected I want to display a error msg as 'No records selected'. If more than 1 record selected then display 'select 1 record'. If 1 row selected then call a procedure. How can I achieve this using Java Script?

«1

Answers

  • Nithyaa
    Nithyaa Member Posts: 10 Green Ribbon

    Someone please help.

  • Veerendra Patil
    Veerendra Patil Member Posts: 586 Gold Badge

    Hi,

    If you want this to happen on DA on some button click - then

    DA action - Execute JS

    var gridView = apex.region("your-IG-static-id").widget().interactiveGrid("getViews").grid;

    var records = gridView.getSelectedRecords();

    var recs = records.length;

    if (recs = 0) {apex.message.alert("No records selected")};

    if (recs > 1) {apex.message.alert("Select 1 record")};

    if (recs = 1) {

    apex.server.process("CALL_YOUR_AJAX_PROCESS", {

           x01: $v("PAGE_ITEM_1") ,// Parameters to pass to AJAX process if any

    x02: $v("PAGE_ITEM_2") ,// Parameters to pass to AJAX process if any

          }, {

            //pageItems: ''

            //dataType: 'text'

          }).done(function (pData) {

            console.log(pData);

          });

    };


    Create an AJAX process and call your procedure there.

    access the variables as apex_application.g_x01, apex_application.g_x02 ..etc


    Thanks,

    Veerendra.

  • Nithyaa
    Nithyaa Member Posts: 10 Green Ribbon

    Thanks a lot Veerendra. Can you also share how to display this error message in inline notification?

  • Veerendra Patil
    Veerendra Patil Member Posts: 586 Gold Badge

    Hi,

    You can try like below.

    apex.message.clearErrors(); // Clear the previous errors if any.

    apex.message.showErrors([ // This is an array

     {

      type: apex.message.TYPE.ERROR,

      location: ["page", "inline"], // Remove Inline if the message is only at the Page level

      pageItem: "P1_DEMO", /// This can be commented if you want to show the error only on Page level.

      message: "Your error Message",

      unsafe: false

     }

    ]);


    Thanks

  • Nithyaa
    Nithyaa Member Posts: 10 Green Ribbon

    Thank you. Can you please check this code. It is giving syntax error and I couldn't find what's wrong.


    var gridView = apex.region("VALID").widget().interactiveGrid("getViews").grid;

    var records = gridView.getSelectedRecords();

    var recs = records.length;

    apex.message.clearErrors();

    if (recs = 0)  // this is working fine

    apex.message.showErrors([ 

    {

     type: apex.message.TYPE.ERROR,

     location: ["page"], 

     message: "Please Select a Transaction",

     unsafe: false

     }

    ]);

    if (recs > 1)  // this is working fine

    apex.message.showErrors([ 

    {

     type: apex.message.TYPE.ERROR,

     location: ["page"], 

     message: "Please Select just one Transaction",

     unsafe: false

    }

    ]);

    if (recs = 1) // this is not working. here based on the selection of a record I need to pass a column value to my AJAX process. column name is 'TRX_ID' and its a hidden column.

    {

    apex.server.process("manual_transmit", {

        //x01: $v("P12_TRX_ID") // Parameters to pass to AJAX process if any

      }, {

       }).done(function (pData) {

       console.log(pData);

      });

    };


    AJAX process SQL:

    DECLARE

    l_username    VARCHAR2(1000);

    l_trx_id      NUMBER;

    l_error_msg   VARCHAR2(1000);

    l_reason      VARCHAR2(1000);

    l_val_only    BOOLEAN DEFAULT TRUE;

    v_url         VARCHAR2(1000);


    BEGIN

      l_user_name := V('APP_USER');

      v_url := apex_page.get_url(p_page => 50, p_items => :P50_TRX_ID, p_values => trx_id);

      xxs2c_dsh_inv_list_pkg.mark_as_manual_transmission (l_username, l_trx_id, l_error_msg, l_reason, l_val_only);

         IF l_error_msg IS NOT NULL 

        THEN 

        :P12_ERROR_MSG := l_error_msg;

        ELSE 

        apex_util.redirect_url(p_url => v_url);

        END IF;

    END;



    Please help.


     



        

  • Nithyaa
    Nithyaa Member Posts: 10 Green Ribbon

    Can anyone help me to get this please.

  • Veerendra Patil
    Veerendra Patil Member Posts: 586 Gold Badge

    Hi,

    Can you try below please?

    function showErrorMessage(pMessage){

    apex.message.showErrors([ 

    {

     type: apex.message.TYPE.ERROR,

     location: ["page"], 

     message: pMessage,

     unsafe: false

     }

    ]);

    }


    var gridView = apex.region("VALID").widget().interactiveGrid("getViews").grid;

    var records = gridView.getSelectedRecords();

    var recs = records.length;

    var trxID = 0;

    apex.message.clearErrors();


    if (recs = 0) showErrorMessage("Please Select a Transaction") // this is working fine

    if (recs > 1) showErrorMessage("Please Select just one Transaction")// this is working fine


    if (recs = 1) // this is not working

    {

    $.each(records , function(i, r) {

    trxID = gridView.model.getValue(r, "TRX_ID");

    });

    apex.server.process("manual_transmit", {

      x01: trxID // Parameters to pass to AJAX process if any

     }, {

      }).done(function (pData) {

      console.log(pData);

      if(pData.success == "ERROR") showErrorMessage(pData.message)

      if(pData.success == "OK") apex.navigation.redirect(pData.message);

     });

    };


    -- AJAX-----------------

    DECLARE

    l_username  VARCHAR2(1000);

    l_trx_id   NUMBER;

    l_error_msg  VARCHAR2(1000);

    l_reason   VARCHAR2(1000);

    l_val_only  BOOLEAN DEFAULT TRUE;

    v_url     VARCHAR2(1000);

    BEGIN

     l_user_name := :APP_USER;

     l_trx_id := to_number(apex_application.g_x01); -- Since you defined l_trx_id as NUMBER.

      

     v_url := apex_page.get_url(p_page => 50, p_items => :P50_TRX_ID, p_values => l_trx_id);

     xxs2c_dsh_inv_list_pkg.mark_as_manual_transmission (l_username, l_trx_id, l_error_msg, l_reason, l_val_only);

      

       IF l_error_msg IS NOT NULL 

      THEN 

      apex_json.open_object;

    apex_json.write('success', 'ERROR');

    apex_json.write(message, l_error_msg);

      apex_json.close_object;

      ELSE 

      apex_json.open_object;

    apex_json.write('success', 'OK');

    apex_json.write(message, v_url);

      apex_json.close_object;

      END IF;

    END;

    Let me know if you have any issues.

    Thanks,

  • Nithyaa
    Nithyaa Member Posts: 10 Green Ribbon

    Hello,


    Thanks for your comment. This is still now working. When is select a row and press the button either it should throw an error or redirect to another page. Both are not happening. I see l_trx_id and v_return_url  returing correct value. For testing just assigned those value into an item and checked. Really not sure where it is going wrong.


    DECLARE


    l_username  VARCHAR2(1000);

    l_trx_id   NUMBER;

    l_error_msg  VARCHAR2(1000);

    l_reason   VARCHAR2(1000);

    l_val_only  BOOLEAN := true;

    v_url     VARCHAR2(1000);

    l_message VARCHAR2(1000);

    v_return_url varchar2(500) := null;

    v_url_text varchar2(500) := null;


    BEGIN


     l_username := V('APP_USER');


     l_trx_id := to_number(apex_application.g_x01); -- Since you defined l_trx_id as NUMBER.


     --:P12_ERROR_MSG := l_trx_id;

     --v_url := apex_page.get_url(p_page => 50, p_items => :P50_TRX_ID, p_values => l_trx_id);


     v_url_text := 'f?p='||:APP_ID||':50:'||:APP_SESSION;

     v_return_url := apex_util.prepare_url(v_url_text);


     --:P12_COUNT := v_return_url;


     xxs2c_dsh_inv_list_pkg.mark_as_manual_transmission (l_username, l_trx_id, l_error_msg, l_reason, l_val_only);


      IF l_error_msg IS NOT NULL 

       THEN 

       apex_json.open_object;

       apex_json.write('success', 'ERROR');

       apex_json.write(l_message, l_error_msg);

       apex_json.close_object;

       ELSE 

       apex_json.open_object;

       apex_json.write('success', 'OK');

       apex_json.write(l_message, v_return_url);

       apex_json.close_object;

     END IF;


    END;

  • Nithyaa
    Nithyaa Member Posts: 10 Green Ribbon

    Even the JS doesn't work. I used this.

    var gridView = apex.region("VALID").widget().interactiveGrid("getViews").grid;


    var records = gridView.getSelectedRecords();


    var recs = records.length;


    var trxID = 0;


    alert(recs);


    apex.message.clearErrors();


    if (recs == 0) 


    apex.message.showErrors([ 


     {


     type: apex.message.TYPE.ERROR,


     location: ["page"], 


     message: "Please Select a Transaction",


     unsafe: false


     }


    ]);


    if (recs > 1) 



    apex.message.showErrors([ 


     {


     type: apex.message.TYPE.ERROR,


     location: ["page"], 


     message: "Please Select just one Transaction",


     unsafe: false


     }


    ]);


    if (recs == 1) {


    $.each(records, function(i, r) {


    trxID = gridView.model.getValue(r, "TRX_ID");


    alert(trxID);


    });


    apex.server.process("manual_transmit", {

      

        x01: trxID,


       }, {


        dataType: 'text'


       }).done(function (pData) {


        console.log(pData);


     if(pData.success == "ERROR") showErrorMessage(pData.message)


     if(pData.success == "OK") apex.navigation.redirect(pData.message);


       });


    };

  • Veerendra Patil
    Veerendra Patil Member Posts: 586 Gold Badge

    Hi,

    Can you create an example on apex.oracle.com please?

    Cant debug here.

    Thanks,