// Create a GlideRecord for the 'cmdb_ci' table var cmdbCiGr = new GlideRecord('cmdb_ci'); cmdbCiGr.addEncodedQuery('sys_class_name=cmdb_ci_computer^serial_numberISNOTEMPTY^assetISEMPTY'); cmdbCiGr.query(); // Create a GlideRecord for the 'alm_asset' table var almAssetGr = new GlideRecord('alm_asset'); almAssetGr.addEncodedQuery('ci=NULL^serial_numberISNOTEMPTY'); almAssetGr.query(); // Loop through 'alm_asset' records and check for matching serial numbers in 'cmdb_ci' while (almAssetGr.next()) { var serialNumber = almAssetGr.serial_number; // Create a new GlideRecord for 'cmdb_ci' and query based on serial number var cmdbCiGrBySerial = new GlideRecord('cmdb_ci'); cmdbCiGrBySerial.addQuery('serial_number', serialNumber); cmdbCiGrBySerial.query(); if (cmdbCiGrBySerial.next()) { // Do something with the matching records gs.log('Match found: ' + serialNumber); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter