Name
global.AddressMgmtUtilsSNC
Description
Address management related APIs
Script
var AddressMgmtUtilsSNC = Class.create();
AddressMgmtUtilsSNC.prototype = {
initialize: function() {},
isAddressSharingEnabled: function() {
return gs.getProperty(AddressMgmtConstants.PROPERTY_ENABLE_ACCOUNT_ADDRESS_SHARING, "false") == "true";
},
getLocationsForAccHierarchy: function(account) {
if (!account)
return [];
var accountLocations = [];
var includeWholeTree = true;
var accounts = new global.CSManagementUtils().getAccountsFromHierarchy(account, includeWholeTree);
if (accounts && accounts.length > 0) {
var accAddressGR = new GlideRecord(AddressMgmtConstants.TABLE_ACCOUNT_ADDRESS_RELATIONSHIP);
accAddressGR.addQuery('account', 'IN', accounts.join(','));
accAddressGR.query();
while (accAddressGR.next()) {
var locationValue = accAddressGR.getValue('location');
if (accountLocations.indexOf(locationValue) < 0)
accountLocations.push(locationValue);
}
}
return accountLocations;
},
/*
Returns list of locations that are associated with the given account
account - sys_id of account
*/
getLocationsForAccount: function(account) {
if (!account)
return [];
if(this.isAddressSharingEnabled()){
return this._getLocationsFromAccAddressTable(account);
}
else{
return this._getLocationsFromLocationTable(account);
}
},
_getLocationsFromAccAddressTable: function(account){
if (!account)
return [];
var accountLocations = [];
var accAddressGR = new GlideRecord(AddressMgmtConstants.TABLE_ACCOUNT_ADDRESS_RELATIONSHIP);
accAddressGR.addQuery('account', account);
accAddressGR.query();
while (accAddressGR.next()) {
accountLocations.push(accAddressGR.getValue('location'));
}
return accountLocations;
},
_getLocationsFromLocationTable: function(account){
if (!account)
return [];
var accountLocations = [];
var locationGR = new GlideRecord(AddressMgmtConstants.TABLE_LOCATION);
if(!locationGR.isValidField('account'))
return [];
locationGR.addQuery('account', account);
locationGR.query();
while (locationGR.next()) {
accountLocations.push(locationGR.getUniqueValue());
}
return accountLocations;
},
getAccountLocationsRefQual: function(account) {
var query = '';
var ep = new GlideScriptedExtensionPoint().getExtensions(AddressMgmtConstants.ADDRESS_MGMT_EXTENSION_POINT);
for (var i = 0; i < ep.length; i++) {
var point = ep[i];
query = point.getAccountLocationsRefQual(account);
}
return query;
},
isAccountLocation: function(location) {
if (!location)
return false;
var gr = new GlideRecord(AddressMgmtConstants.TABLE_ACCOUNT_ADDRESS_RELATIONSHIP);
gr.addQuery('location', location);
gr.setLimit(1);
gr.query();
return gr.hasNext();
},
isMultipleAccountAssocToLocation: function(location) {
if (!location)
return false;
var gr = new GlideRecord(AddressMgmtConstants.TABLE_ACCOUNT_ADDRESS_RELATIONSHIP);
gr.addQuery('location', location);
gr.setLimit(2);
gr.queryNoDomain();
return gr.getRowCount() > 1;
},
canAccountManagerAccessLocation: function(location) {
if (!location)
return false;
var accountAddressReln = new GlideRecord(AddressMgmtConstants.TABLE_ACCOUNT_ADDRESS_RELATIONSHIP);
accountAddressReln.addQuery("location", location.getUniqueValue());
accountAddressReln.addQuery("account", "DYNAMIC", "badfcbf60fe210103ff81b41ff767e40");
accountAddressReln.setLimit(1);
accountAddressReln.query();
return accountAddressReln.hasNext();
},
isDuplicateEntry: function(gr) {
if (!gr || !gr.account || !gr.location)
return true;
var accAddressGr = new GlideRecord(AddressMgmtConstants.TABLE_ACCOUNT_ADDRESS_RELATIONSHIP);
accAddressGr.addQuery('account', gr.account);
accAddressGr.addQuery('location', gr.location);
accAddressGr.addQuery('sys_id', '!=', gr.getUniqueValue());
accAddressGr.setLimit(1);
accAddressGr.query();
return accAddressGr.hasNext();
},
getConsumerProfileLocationCount: function(location) {
var count = 0;
if (!location)
return count;
var gr = new GlideAggregate(global.AddressMgmtConstants.TABLE_CONSUMER_PROFILE_LOCATION);
gr.addQuery('location', '=', location);
gr.addAggregate('COUNT');
gr.query();
if(gr.next()) {
count = parseInt(gr.getAggregate('COUNT'));
}
return count;
},
type: 'AddressMgmtUtilsSNC'
};
Sys ID
766e68c653a101100f16ddeeff7b12c4