3 Replies Latest reply on Dec 18, 2018 1:28 AM by John Snyders-Oracle

    interactive grid record state

    Krisztian, Hegyvari

      Hi,

       

      Is there a way to check if the record selected in an interactive grid:

       

      - is a new record and has never been saved to the database

      - a given column has been updated and has not been saved to the db?

       

      There are actions and items on the form which need to behave differently for new/changed records.

       

      Thanks,

       

      Krisztian

        • 1. Re: interactive grid record state
          Franck N

          Hi,

           

          if it's just a matter of visually identify if a record has been save after an insert in an IG then it's pretty easy.By just observing the Grid itself, you will see 2 infos:

               - one will be a blue triangle at the top right corner of every cell where a Data is not yet saved in the DB

               - and or a light green back ground colour on the row.

           

           

          There are actions and items on the form which need to behave differently for new/changed records.

           

           

          The question remains open: how should they behave? could you provide a Use Case?

           

          regards,

          Franck

          • 2. Re: interactive grid record state
            Krisztian, Hegyvari

            Thanks, I would like to be able to check the state programmatically.

             

            Use case:

             

            I have a grid and next to the grid I have a cascading LOV in a shuttle. The LOV is filled by a select query and the where clause contains the id of the record in the grid. Actually, the shuttle displays the employees of a company, the company record is in the grid. If the user adds a new record to the grid, hence a new company, which does not even have a primary id yet (only the one auto generated by the grid, which is interestingly enough a string (t1001) although the columns is numeric) the LOV of the shuttle cannot be refreshed. To be honest, I do not even want to display the shuttle. I can go into the model layer behind the grid and check if the ID starts with the letter "t", but I wondered if there would be a nicer way to do this.

             

            I could also have buttons under the grid starting plsql batches on the server, where I would disable the button if the record has not been saved to the database yet.

            • 3. Re: interactive grid record state
              John Snyders-Oracle

              Hi Krisztian,

               

              This is reasonably easy to do. In the following code I assume the static id of the IG region is "emp". You can try this out with editable grids in the Sample Interactive Grids app.

               

              var m = apex.region("emp").call("getCurrentView").model;

              var rec = apex.region("emp").call("getSelectedRecords")[0];

              m.getRecordMetadata(m.getRecordId(rec)); // returns the metadata

               

              See https://docs.oracle.com/database/apex-18.2/AEXJS/model.html#.RecordMetadata for all the metadata properties. For example inserted property when true means the record was inserted. You can drill down into specific fields with the fields property to tell if a field has changed.

               

              Using inserted property is better than looking at the id to see if it starts with "t" because that is configurable and if you ever have a string key column it could just happen to start with a "t". Don't worry about the "t1001" values they are just temporary placeholders because the server DB is the only one that assign the actual primary key when the record is inserted in the DB but the client and server need some way to refer to the record before it is saved.

               

              Regards,

              -John