Highlighted
Super Contributor.. Super Contributor..
Super Contributor..
383 views

Structured Array Manipulation

Jump to solution
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”?
0 Likes
1 Solution

Accepted Solutions
Highlighted
Knowledge Partner
Knowledge Partner

Re: Structured Array Manipulation

Jump to solution

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;

Regards,
Breno Abreu

If you feel this was helpful please click the KUDOS! thumb below!

View solution in original post

2 Replies
Highlighted
Knowledge Partner
Knowledge Partner

Re: Structured Array Manipulation

Jump to solution

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;

Regards,
Breno Abreu

If you feel this was helpful please click the KUDOS! thumb below!

View solution in original post

Highlighted
Super Contributor.. Super Contributor..
Super Contributor..

Re: Structured Array Manipulation

Jump to solution
That's what I was looking for, thank you.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.