Duplicate Row In IG - Oracle Apex

var validity, message,
    ui = this.data;
 
(function($)
{
 
    function update(model)
    {
        var salKey = model.getFieldKey("SAL"),
            empnoKey = model.getFieldKey("EMPNO"),
             recObj = [],
             recArray = [];
        model.forEach(function(record, index, id)
        {
            var sal = parseInt(record[salKey], 10),  // record[salKey] should be a little faster than using model.getValue in a loop
                empno = parseInt(record[empnoKey], 10),
                meta = model.getRecordMetadata(id);
if (!isNaN(sal) && !meta.deleted && !meta.agg)
{
   recObj = {ID: id, salary: sal, EMPNO: empno};
   recArray.push(recObj);                   
}       
});       
        //************************mark found duplicates*************************       
        var duplicateIds = recArray
                         .map(e => e['salary'])
                         .map((e, i, final) => final.indexOf(e) !== i && i)
                         .filter(obj => recArray[obj])
                         .map(e => recArray[e]["salary"]);
        var duplObjects = recArray.filter(obj=> duplicateIds.includes(obj.salary));
             
        if (duplicateIds.length > 0)
        {
          apex.message.clearErrors();     
       
           // Now show new errors
          apex.message.showErrors([
                {
                    type:       "error",
                    location:   "page",
                    message:    "Duplicates found on rows!" + "\r\n" + JSON.stringify(duplObjects),
                    unsafe:     false
                }
                  ]);
          }
          else {
              apex.message.clearErrors();
               
              }             
    }


    $(function() {
   
        $("#emp").on("interactivegridviewmodelcreate", function(event, ui) {
            var sid, model = ui.model;
           
           
            if ( ui.viewId === "grid" ) {
                sid = model.subscribe( {
                    onChange: function(type, change) {
                        if ( type === "set" ) {
                            // don't bother to recalculate if other columns change
                            if (change.field === "SAL" ) {
                                update( model );
                            }
                        } else if (type !== "move" && type !== "metaChange") {
                            // any other change except for move and metaChange affect the calculation
                            update( model );
                        }
                    }
                } );
                // if not lazy loaded there is no notification for initial data so update
                update(model);
           
                model.fetchAll(function() {});
            }
        });
    });
})(apex.jQuery);

Comments

Popular posts from this blog

Telegram Integration with Oracle

The username or password for the connection pool named |apex||, are invalid, expired, or the account is locked

Enabled SQL Developer Web (SDW) & ORDS Database API ORDS 19.4