6 Replies Latest reply on Jan 17, 2019 7:25 PM by Eslam_Elbyaly

    Set cell value of selected record

    Eslam_Elbyaly

      Apex 18.2

      - I have a region(order_detail) which has a column(qty) and a static id of "order_detail".

      - a button that should assign value of "9" for "qty" field of the "current record" or "selected record" as per you call it(It's the last record the user navigated to) when it's clicked.

       

      I have created a dynamic action executes the following javascript code when the button is clicked,

      var widget      = apex.region('order_detail').widget();

      var grid        = widget.interactiveGrid('getViews','grid'); 

      var model       = grid.model;

      var x = model.getSelectedRecords();

      var b = model.getRecordId(x);

      model.setRecordValue(b, "QTY", 9);

      when I run the page it shows 2 errors,

      1- Unchecked runtime.lastError: The message port closed before a response was received.

      2-

      Uncaught TypeError: Cannot read property '0' of null
          at Object._getIdentity (interactiveGrid.min.js?v=18.2.0.00.12:2)
          at Object.setValue (interactiveGrid.min.js?v=18.2.0.00.12:1)
          at Object.setRecordValue (interactiveGrid.min.js?v=18.2.0.00.12:1)
          at Object.javascriptFunction (f?p=11561:8:110771644048721::::::445)
          at Object.da.doAction (desktop_all.min.js?v=18.2.0.00.12:23)
          at Object.da.doActions (desktop_all.min.js?v=18.2.0.00.12:23)
          at HTMLButtonElement.<anonymous> (desktop_all.min.js?v=18.2.0.00.12:23)
          at Function.each (desktop_all.min.js?v=18.2.0.00.12:2)
          at r.fn.init.each (desktop_all.min.js?v=18.2.0.00.12:2)
          at Object.da.actions (desktop_all.min.js?v=18.2.0.00.12:23)
      

       

      Edited:

      Workspace= MY_WS

      user= forhelp

      password= forhelppwd

      app= POS

      page= 8

        • 1. Re: Set cell value of selected record
          Mahmoud_Rabie

          Hi Eslam

           

          Could you reproduce it on apex.oracle.com to help you fix it there.

           

          In addition to app and page numbers, please provide workspace name and a developer account.

           

          Regards

          Mahmoud

          • 2. Re: Set cell value of selected record
            Eslam_Elbyaly

            Hi Mahmoud. Thanks for prompt reply.

            Edited:

            Workspace= MY_WS

            user= forhelp

            password= forhelppwd

            app= POS

            page= 8

            the dynamic action is called "assign_qty" and it should fire when button(1) is clicked.

            • 3. Re: Set cell value of selected record
              Mahmoud_Rabie

              Solution

              (1) Assign a static ID ( QTY ) to the corresponding IG column

               

              (2) The DA must not fire on Initialization

               

              (3) It is better to let DA execute the JS functions which are defined in (4).

               

              (4) Add a CSS class to all keypad buttons to use it as jQuery Selector. The next step I would recommend is to get the value of the pressed button to pass it to the assignQuantity function. In addition, you could assign a PRICE as data for each card in the products custom classic report on the right side. If you find a difficulty to do that, you could open a new thread to help you there.

               

              (5) Functions and Global Variables that are called in DAs

              /*Global Variables*/
              var widget;
              var grid;  
              var model; 
              
              /*Functions*/
              function addItem(p_price){
                  //insert new record on a model
                  var myNewRecordId = model.insertNewRecord();
              
                  //get the new record
                  var myNewRecord = model.getRecord(myNewRecordId);
              
                  //update record values
                  model.setValue(myNewRecord, "PRICE", p_price);
              }
              function assignQuantity(p_qty){
                  var selRecord = grid.getSelectedRecords()[0];
                  model.setValue(selRecord,"QTY", p_qty);
              }
              

               

              (6) Execute on Page Load once, not on each DA

               widget      = apex.region('order_detail').widget();
               grid        = widget.interactiveGrid('getViews','grid');  
               model       = grid.model; 
              

               

              Now, please check.

               

              I hope that solves your problem.

               

              Regards

              Mahmoud

              • 4. Re: Set cell value of selected record
                Eslam_Elbyaly

                Thanks a lot Mahmoud for your contribution. But there is a little bug and some questions if you do not mind,

                Edited credentials:

                Workspace= MY_WS

                user= forhelp

                password= forhelppwd

                app= POS

                page= 8

                1- Run the page. Click an item. The new record is created. Click on button(1). It will set qty to 9. Click another item. It will not select the new record. It will still be selecting the first one and if you click button(1) again it will not set the qty of the newly created record unless you select it by the mouse. Only then you can add new items and it will select the new records created normally and you will be able to set qty for newly created rows.

                https://youtu.be/X0adj-zG8s4

                 

                2- I used setRecordValue instead of using setValue method. It takes the recordId as a parameter, so there will be no need for

                1.   //get the new record 
                2.     var myNewRecord = model.getRecord(myNewRecordId); 

                3- Correct me if I am wrong...

                [0] is the index of the element of the array returned by "getSelectedRecord" method and it refers to the temp primary key generated by Apex?

                 

                Why use [0] when "setValue" accepting an "array" as an argument not an "array element"?

                I tried using  "getSelectedRecord" without [0] but it did not work?!

                 

                4- Is there an advantage of creating 2 variables...

                1. widget      = apex.region('order_detail').widget(); 
                2. grid        = widget.interactiveGrid('getViews','grid');

                over 1 like this

                grid = apex.region('order_detail').widget().interactiveGrid('getViews','grid');

                ?

                5- If I understand correctly, "interactiveGrid" is a method that belongs to the Jquery object returned by the "widget()" function. Where can I read about "interactiveGrid" method and other method/properties of the "widget" jquery object? It's not documented. I checked!

                • 5. Re: Set cell value of selected record
                  Mahmoud_Rabie

                  Eslam_Elbyaly wrote:

                   

                  Thanks a lot Mahmoud for your contribution. But there is a little bug and some questions if you do not mind,

                  Edited credentials:

                  Workspace= MY_WS

                  user= forhelp

                  password= forhelppwd

                  app= POS

                  page= 8

                  1- Run the page. Click an item. The new record is created. Click on button(1). It will set qty to 9. Click another item. It will not select the new record. It will still be selecting the first one and if you click button(1) again it will not set the qty of the newly created record unless you select it by the mouse. Only then you can add new items and it will select the new records created normally and you will be able to set qty for newly created rows.

                  https://youtu.be/X0adj-zG8s4

                   

                  2- I used setRecordValue instead of using setValue method. It takes the recordId as a parameter, so there will be no need for

                  1. //get the new record
                  2. var myNewRecord = model.getRecord(myNewRecordId);

                  3- Correct me if I am wrong...

                  [0] is the index of the element of the array returned by "getSelectedRecord" method and it refers to the temp primary key generated by Apex?

                   

                  Why use [0] when "setValue" accepting an "array" as an argument not an "array element"?

                  I tried using "getSelectedRecord" without [0] but it did not work?!

                   

                  4- Is there an advantage of creating 2 variables...

                  1. widget = apex.region('order_detail').widget();
                  2. grid = widget.interactiveGrid('getViews','grid');

                  over 1 like this

                  grid = apex.region('order_detail').widget().interactiveGrid('getViews','grid');

                  ?

                  5- If I understand correctly, "interactiveGrid" is a method that belongs to the Jquery object returned by the "widget()" function. Where can I read about "interactiveGrid" method and other method/properties of the "widget" jquery object? It's not documented. I checked!

                   

                  (1) It is not bug. It is the default behavior of IG. You could override it by searching for JS to default select the newly created row. This thread might help you

                  Interactive Grid - First row selected by default. Have the method changed for disabling this in APEX 18?

                   

                  (2) Not clear for me.

                   

                  (3) As the function returns the array of selected rows, [0] is the first one.

                   

                  (4) For your context, the second form is preferred over the first one as you don't need widget.

                   

                  (5) To read more and understand how IG works, I would recommend the following resources

                  --> Up-to-date IG cook book blog posts by John Snyders-Oracle. He is the mind behind IG of APEX Development Team.

                  --> Java Script API documentation

                  --> IG Cheat Sheet

                   

                  I hope that helps

                   

                  Regards

                  Mahmoud

                  1 person found this helpful
                  • 6. Re: Set cell value of selected record
                    Eslam_Elbyaly

                    (1) It is not bug. It is the default behavior of IG. You could override it by searching for JS to default select the newly created row. This thread might help you

                    Interactive Grid - First row selected by default. Have the method changed for disabling this in APEX 18?

                    I think it is. If you noticed, the process work perfectly when I change the selection manually once. It does not work before doing so.

                    - The thread you referred me to is asking about disabling selection. And the solutions they are referring to is already implemented in my case.

                    The JavaScript Initialization Code of my IG> Attributes is

                    function(config) {
                    
                    
                      config.initialSelection = true;
                    
                    
                      return config;
                    
                    
                    }
                    

                     

                    Edited:

                    - I tried adding line no. 04 to the function but did nothing...

                    function addItem(p_price){  
                        //insert new record on a model  
                        var myNewRecordId = model.insertNewRecord();  
                        var x = model.setSelectionState(myNewRecordId,true);       -- the added line
                        //get the new record  
                        var myNewRecord = model.getRecord(myNewRecordId);  
                      
                        //update record values  
                        model.setValue(myNewRecord, "PRICE", p_price);  
                        model.setValue(myNewRecord,"ITEM_NAME", "Pizza");  
                    }