Structured Array Manipulation

I’ve got a coding question hoping someone can help with. In a CI record there are tables that display various data items. Things like support contacts, IP information, etc. This data is manually maintained on the CI record and is stored in a structured array in the database. All that is fine.
Now let’s say I have 3 rows in one of those tables. If I delete the 1st row and save the record, the data in row 2 and 3 will stay in row 2 and 3, while row 1 will now be blank. The application doesn’t natively compress the existing entries to remove a row of empty strings. It’s not really an issue if there are only 3 rows, but if the table has 15-20 rows blank spots are more troublesome.
So my question is, does anyone have a method of doing this “compaction”?
  • Verified Answer

    You can use the function bellow to remove Null and Duplicate (extract from HP 9.40) or construct one.

     

    Function in tableUtil script.

    function removeNullAndDuplicate(record,field)
    {
    var list = field;
    var length=system.functions.lng(list);
    var results = new Array();
    var addIndex=0;
    for (var i=0;i<length; i)
    {
    if (list[i] != null && list[i].length>0)
    {
    var dup = false;
    for(var k=0;k<addIndex; k)
    {
    if(results[k] == list[i])
    {
    dup = true;
    break;
    }
    }
    if(!dup)
    {
    results[addIndex] = list[i];
    addIndex;
    }
    }
    }
    return results;
    }

     

    Example of call:

    var results = system.library.tableUtil.removeNullAndDuplicate(system.vars.$file,system.vars.$file.assets);
    system.vars.$file.assets = results;

  • That's what I was looking for, thank you.