logo

NJP

Get list of unique vendors and manufacturers

Import · Jan 12, 2021 · article

Below script gives unique list of vendor and manufacturer names

var vendorHash = {};var ManufacturerHash = {};var grCi = new GlideRecord('cmdb_ci');grCi.query();while(grCi.next()) { ManufacturerHash[grCi.getDisplayValue('manufacturer')] = 1; vendorHash[grCi.getDisplayValue('vendor')] = 1;}printHash(ManufacturerHash, 'Manufacturer');

printHash(vendorHash, 'Vendor');

function printHash(hashArray, Name) { for (var k in hashArray) { // use hasOwnProperty to filter out keys from the Object.prototype if (hashArray.hasOwnProperty(k)) { gs.print( Name + "|"+ k + "|"+ hashArray[k]); }}

}

var vendorHash = {};var ManufacturerHash = {};var grCi = new GlideRecord('cmdb_ci');grCi.query();while(grCi.next()) { ManufacturerHash[grCi.getDisplayValue('manufacturer')] = 1; vendorHash[grCi.getDisplayValue('vendor')] = 1;}printHash(ManufacturerHash, 'Manufacturer');

printHash(vendorHash, 'Vendor');

function printHash(hashArray, Name) { for (var k in hashArray) { // use hasOwnProperty to filter out keys from the Object.prototype if (hashArray.hasOwnProperty(k)) { gs.print( Name + "|"+ k + "|"+ hashArray[k]); }}

}

Labels:

image

View original source

https://www.servicenow.com/community/now-platform-articles/get-list-of-unique-vendors-and-manufacturers/ta-p/2319519