Name
global.ServiceSubscriptionUtilsSNC
Description
No description available
Script
var ServiceSubscriptionUtilsSNC = Class.create();
ServiceSubscriptionUtilsSNC.prototype = {
initialize: function() {
this.constants = new global.SPMFoundationConstants();
},
getMySubscriptions: function() {
var answer = new Object();
this._addUser(answer);
this._addGroup(answer);
var u = GlideUser.getUserByID(gs.getUserID());
this._addDept(answer, u.getDepartmentID());
this._addLocation(answer, u.getLocation());
this._addCompany(answer, u.getCompanyID());
// convert to an ArrayList
var a = new Array();
for (key in answer)
a.push(key);
return a;
},
/**
* Get associated offerings for a catalog item. These are offerings associated via
* "Available for Subscribers" and "Not Available for Subscribers" tables.
* Only get offering that have any subscribers from offering subscriber tables.
* @param tableName - Either "Available for Subscribers" or "Not Available for Subscribers" tables
* @param cat_item - Catalog item getting associated offerings for
* @return - List of offerings
*/
getCatItemOfferings: function(tableName, cat_item) {
var gr = new GlideRecord(tableName);
gr.addQuery('sc_cat_item', cat_item);
gr.query();
if (!gr.hasNext())
return null;
answer = new Array();
while (gr.next()) {
var offering = gr.getValue('service_offering');
// check if "valid" service offering has subscribers
if (this._checkOfferinghasSubscribers(offering))
answer.push(offering);
}
return answer;
},
/**
* Check if offering has any subscribers from subscriber tables
* @param offeringId - offering to check
* @return - true or false if offering has any subscribers
*/
_checkOfferinghasSubscribers: function(offeringId) {
if (this._checkSubscriberTable(this.constants.SERVICE_SUBSCRIBE_SYS_USER, offeringId))
return true;
if (this._checkSubscriberTable(this.constants.SERVICE_SUBSCRIBE_SYS_USER_GRP, offeringId))
return true;
if (this._checkSubscriberTable(this.constants.SERVICE_SUBSCRIBE_DEPARTMENT, offeringId))
return true;
if (this._checkSubscriberTable(this.constants.SERVICE_SUBSCRIBE_LOCATION, offeringId))
return true;
if (this._checkSubscriberTable(this.constants.SERVICE_SUBSCRIBE_COMPANY, offeringId))
return true;
return false;
},
// check to see if any records exist in table associated to item_id
_checkSubscriberTable: function(tableName, offeringId) {
var gr = new GlideRecord(tableName);
gr.addQuery('service_offering', offeringId);
gr.query();
if (gr.hasNext())
return true;
return false;
},
_addUser: function(answer) {
var gr = new GlideRecord(this.constants.SERVICE_SUBSCRIBE_SYS_USER);
gr.addQuery('sys_user', gs.getUserID());
this._query(gr, answer);
},
_addGroup: function(answer) {
var groups = GlideUser.getMyGroups(gs.getUserID());
if (groups.isEmpty())
return;
var gr = new GlideRecord(this.constants.SERVICE_SUBSCRIBE_SYS_USER_GRP);
gr.addQuery('sys_user_group', groups);
this._query(gr, answer);
},
_addDept: function(answer, dept_id) {
var gr = new GlideRecord(this.constants.SERVICE_SUBSCRIBE_DEPARTMENT);
gr.addQuery('cmn_department', dept_id);
this._query(gr, answer);
},
_addLocation: function(answer, location_id) {
var gr = new GlideRecord(this.constants.SERVICE_SUBSCRIBE_LOCATION);
gr.addQuery('cmn_location', location_id);
this._query(gr, answer);
},
_addCompany: function(answer, company_id) {
var gr = new GlideRecord(this.constants.SERVICE_SUBSCRIBE_COMPANY);
gr.addQuery('core_company', company_id);
this._query(gr, answer);
},
_query: function(gr, answer) {
gr.query();
while (gr.next())
answer[gr.service_offering + ''] = true;
}
};
Sys ID
ca186904eb2321108e6fd7ac785228b2