Blog

Unprocessed Accounts

Report on Accounts without Contacts, Assets, Contracts, or Entitlements.

Script Include

Script Include: SNEReportUtil
Client Callable: true
Accessible from: All application scopes
Script:
var SNEClientUtil = Class.create();
SNEClientUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	filterUnprocessedAccounts : function() {
		var accounts = [];
		var grCA = new GlideRecord('customer_account');
		grCA.addEncodedQuery('customer=true');
		grCA.query();
		while(grCA.next()) {
			var contacts = getAccountCount('customer_contact', grCA.sys_id);
			var assets = getAccountCount('alm_asset', grCA.sys_id);
			var contracts = getAccountCount('ast_contract', grCA.sys_id);
			var entitlements = getAccountCount('service_entitlement', grCA.sys_id);
			if (contacts == 0 && entitlements == 0 && assets == 0) {
				accounts.push(grCA.sys_id);
			}
		}
		return accounts;
	},
	getAccountCount : function(table) {
		//Contact Count
		var ga = new GlideAggregate(table,sysID);
		ga.addQuery('account',sysID);
		ga.addAggregate('COUNT');
		ga.query();
		if(ga.next()) {
			return ga.getAggregate('COUNT');
		}
	},
	type: 'SNEClientUtil'
});

Report

Report: Unprocessed Accounts
Source Type: table
Table: Account [customer_account]
Filter: sys ID is one of javascript:new SNEReportUtil().filterUnprocessedAccounts();