Name

sn_install_base.InstallBaseAjaxSNC

Description

Customers should not change this class directly, but rather override methods in the subclass. This class is never called directly.

Script

var InstallBaseAjaxSNC = Class.create();
InstallBaseAjaxSNC.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
  /*
   * Fetch owner fields (Account, Contact, Consumer , Household and Service organization) from the install base item.
   *
   * Return the above result as JSON string.
   *   {
   *    field: display_value,
   *    field_id: sys_id,
   *    field1: display_value,
   *    field1_id: sys_id
   *    ....
   *   }
   */
  getInstallBaseOwnerDetails: function() {
      var installBaseItemSysId = this.getParameter('sysparm_sys_id');
      var response = {};
      if (!installBaseItemSysId) {
          return response;
      }
      var installBaseItemGr = new GlideRecordSecure(global.CSMBaseConstants.INSTALL_BASE_ITEM);
      if (!installBaseItemGr.get(installBaseItemSysId)) {
          return response;
      }
      var fields = new sn_install_base.InstallBaseUtil().getInstallBaseItemOwnerFields();
      for (var idx = 0, len = fields.length; idx < len; idx++) {
          //populate the displayValue and sysId as key-value pair.
          var fieldObj = {
              "display": installBaseItemGr[fields[idx]].getDisplayValue() + '',
              'id': installBaseItemGr[fields[idx]] + ''
          };
          response[fields[idx]] = fieldObj;
      }
      return JSON.stringify(response);
  },

  /*
   * Check whether the given install base item is a last level child (i.e leaf node) or not.
   * 
   * Returns True if it is a leaf node or else returns False.
   */

  isIBItemALeafNode: function() {
      var ib = this.getParameter('sysparm_sys_id');
      var installBaseGr = new GlideRecordSecure(global.CSMBaseConstants.INSTALL_BASE_ITEM);
      installBaseGr.addQuery('parent', ib);
      installBaseGr.query();
      return !installBaseGr.hasNext();
  },

  getSoldProductsForIB: function() {
      var installBaseID = this.getParameter('sysparm_sys_id');
      var installedProductGr = new GlideRecordSecure(global.CSMBaseConstants.M2M_INSTALLED_PRODUCT);
      installedProductGr.addQuery('install_base_item', installBaseID);
  	installedProductGr.setLimit(2);
      installedProductGr.query();
  	var soldProduct;
  	if(installedProductGr.getRowCount() == 1){
  		if(installedProductGr.next()){
  			soldProduct = installedProductGr.getValue('sold_product');
  		}
  	}
      return JSON.stringify(soldProduct);
  },

  type: 'InstallBaseAjaxSNC'
});

Sys ID

4a83f353c359111074658cab3c40ddc6

Offical Documentation

Official Docs: