Name

sn_cmdb_int_util.SoftwareBundleLookupUtils

Description

No description available

Script

var SoftwareBundleLookupUtils = Class.create();
SoftwareBundleLookupUtils.prototype = {
  initialize: function() {},

  loadData: function(import_set_table) {
      var gr = new GlideRecord("sn_cmdb_int_util_bundleid_lookup");
      gr.addQuery("matched", "false");
      gr.addQuery("active", "true");
      gr.orderBy("queried");
      gr.query();
      var bundleIds = [];
      var urlEncodedBundleIds = [];
      while (gr.next()) {
          if (gr.getValue("bundle_id").contains("?")) {
              continue;
          }
          bundleIds.push(gr.getValue("bundle_id"));
          urlEncodedBundleIds.push(encodeURI(gr.getValue("bundle_id")));
          // request batches of 50
          if (bundleIds.length % 50 == 0) {
              this.fetchBundleIds(import_set_table, bundleIds, urlEncodedBundleIds);
              bundleIds = [];
              urlEncodedBundleIds = [];
          }
      }
      if (bundleIds.length > 0) {
          this.fetchBundleIds(import_set_table, bundleIds, urlEncodedBundleIds);
      }
  },

  fetchBundleIds: function(import_set_table, bundleIds, urlEncodedBundleIds) {
      try {
          var inputs = {};
          inputs['bundle_ids'] = urlEncodedBundleIds.join(","); // String 

          // Execute Data Stream Action. 
          var result = sn_fd.FlowAPI.getRunner().datastream('sn_cmdb_int_util.get_mac_software_by_bundle_id').withInputs(inputs).run();
          var stream = result.getDataStream();

          // Process each item in the data stream
          while (stream.hasNext()) {

              // Get a single item from the Data Stream.
              var generatedComplexObj = stream.next();
              // Remove from the bundleIds so we can update the bundleIds we didn't match
              bundleIds.splice(bundleIds.indexOf(generatedComplexObj.bundleId), 1);

              var gr = new GlideRecord("sn_cmdb_int_util_bundleid_lookup");
              gr.addQuery("bundle_id", generatedComplexObj.bundleId);
              gr.query();
              if (gr.next()) {
                  import_set_table.insert({
                      'u_bundle_id': generatedComplexObj.bundleId,
                      'u_artist_id': generatedComplexObj.artistId,
                      'u_artist_name': generatedComplexObj.artistName,
                      'u_track_id': generatedComplexObj.trackId,
                      'u_track_name': generatedComplexObj.trackName,
                      'u_seller_name': generatedComplexObj.sellerName,
                      'u_kind': generatedComplexObj.kind,
                  });
              }
          }
          gr = new GlideRecord("sn_cmdb_int_util_bundleid_lookup");
          gr.addQuery("bundle_id", bundleIds);
          gr.query();
          while (gr.next()) {
              gr.matched = false;
              gr.queried = true;
              gr.update();
          }
      } catch (ex) {
          var message = ex.getMessage();
          gs.error(message);
      } finally {
          stream.close();
      }
  },

  type: 'SoftwareBundleLookupUtils'
};

Sys ID

c8d71968772030100dfa1bfaae5a99d0

Offical Documentation

Official Docs: