- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 10:17 AM
Hi,
We are trying to retrieve the unique values of a table and then stock their sys_id in an array.
I got the unique values of Software Names in an array but don't achieve to get their associate sys_id.
var arrCmdbSpkgID=[];
var arrCmdbSpkgName=[];
var uniqueSpkgName=[];
var uniqueSpkgID=[];
var uniqueArr = new ArrayUtil();
var pkgLogiciel = new GlideRecord('cmdb_ci_spkg');
pkgLogiciel.addEncodedQuery('install_statusNOT IN99,7');
pkgLogiciel.query();
while(pkgLogiciel.next())
{
arrCmdbSpkgID.push(pkgLogiciel.sys_id.toString());
arrCmdbSpkgName.push(pkgLogiciel.getValue('name'));
}
uniqueSpkgName = uniqueArr.unique(arrCmdbSpkgName);
for (var e = 0; e < arrCmdbSpkgName.length; e++) {
if(uniqueSpkgName){
uniqueSpkgID.push(arrCmdbSpkgID[e]);
}
}
Regards,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 10:51 AM
Hi Nico,
You could use your script down to the unique array without the ID push, then run another GlideRecord on that table with the addQuery line to see if the name is in that joined array, then push the sys_id of each returned record into your ID array, or simplify it with just one GR, doing the unique test with each result before pushing the ID to an array like this:
var arrCmdbSpkgID=[];
var spkgName = '';
var pkgLogiciel = new GlideRecord('cmdb_ci_spkg');
pkgLogiciel.addEncodedQuery('install_statusNOT IN99,7');
pkgLogiciel.orderBy('name');
pkgLogiciel.query();
while (pkgLogiciel.next()){
if (pkgLogiciel.name != spkgName) {
spkgName = pkgLogiciel.name;
arrCmdbSpkgID.push(pkgLogiciel.sys_id.toString());
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 10:41 AM
You are welcome!