Name

sn_itom_licensing.ITOMTriggerLicensableCIsReportStore

Description

No description available

Script

var ITOMTriggerLicensableCIsReportStore = Class.create();
ITOMTriggerLicensableCIsReportStore.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
  initReports: function() {
      var sysIdsList = JSON.parse(this.getParameter('sysparm_selValueStreams'));

      if (gs.nil(sysIdsList))
          return "Nothing to process!";

      var counter = this._triggerJobs(sysIdsList);
      var noOfSelectedVS = sysIdsList.split(",").length;
      return counter == noOfSelectedVS;
  },

  isListingJobRunning: function() {
      var sysIdsList = JSON.parse(this.getParameter('sysparm_selValueStreams'));
      return new sn_itom_licensing.ITOMLicensingUtilsStore().isListingJobRunning(sysIdsList);
  },

  getNavParams : function() {
  	var sysIdsList = JSON.parse(this.getParameter('sysparm_selValueStreams'));
  	var res = {"skuList" : [], "valueStreamList" : []};
  	var gr = new GlideRecord('itom_lu_licensable_cis_trigger');
  	gr.addQuery('sys_id','IN',sysIdsList);
  	gr.query();
  	while(gr.next() && gr.canRead()) {
  		var sku = gr.getValue('sku');
  		var vStream = gr.getValue('value_stream');
  		if(res.skuList.indexOf(sku) == -1)
  			res.skuList.push(sku);
  		if(res.valueStreamList.indexOf(vStream) == -1)
  			res.valueStreamList.push(vStream);				
  	}
  	return JSON.stringify(res);
  },

  cancelListingJobs: function() {
      var sysIdsList = JSON.parse(this.getParameter('sysparm_selValueStreams'));
      var gr = new GlideRecord('itom_lu_licensable_cis_trigger');
      gr.addQuery('sys_id', 'IN', sysIdsList);
      gr.query();
      while (gr.next() && gr.canWrite()) {
          gr.setValue('is_cancel', 'true');
          gr.update();
      }
  },

  _triggerJobs: function(sysIdsList) {
  	var utils = new ITOMLicensingUtilsStore();
      var counter = 0;
      var itomLicCIsReportGR = new GlideRecord('itom_lu_licensable_cis_trigger');
      itomLicCIsReportGR.addQuery('sys_id', 'IN', sysIdsList);
      itomLicCIsReportGR.query();

      while (itomLicCIsReportGR.next() && itomLicCIsReportGR.canWrite()) {
  		var skuType = utils._getSkuType(itomLicCIsReportGR.getValue('sku'));
  		var validLicense = utils._isValustreamSKUPresent(itomLicCIsReportGR.getValue('value_stream').toLowerCase(),
  		                                                 skuType);
  		if(!validLicense) {
  			gs.error(gs.getMessage("Error: License is not valid for {0} {1}", [skuType, itomLicCIsReportGR.getValue('value_stream')]));
  			itomLicCIsReportGR.setValue('status', 'failed');
  			itomLicCIsReportGR.update();
  			continue;
  		}
  		
          var scheduledJobGR = new GlideRecord('sysauto_script');
          var isRecPresent = scheduledJobGR.get('sys_id', itomLicCIsReportGR.getValue('executable_script'));
          var jobSysId;

          if (isRecPresent)
              jobSysId = gs.executeNow(scheduledJobGR);

          if (!gs.nil(jobSysId)) {
              counter++;
              itomLicCIsReportGR.setValue('status', 'running');
          } else {
              gs.error(gs.getMessage("Error: Unable to schedule job for {0}.Make sure you have the required plugin installed.", itomLicCIsReportGR.getValue('value_stream')));
              itomLicCIsReportGR.setValue('status', 'failed');
          }

          var values = [jobSysId, itomLicCIsReportGR.getValue('value_stream')];
          gs.info(gs.getMessage("Job ID for value stream {1} is {0}.", values));
          itomLicCIsReportGR.update();
      }


      return counter;
  },



  type: 'ITOMTriggerLicensableCIsReportStore'
});

Sys ID

e347ab1b5375301046dfddeeff7b12ea

Offical Documentation

Official Docs: