Name
global.CSPConsumerUtils
Description
No description available
Script
var CSPConsumerUtils = Class.create();
CSPConsumerUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//validates if the com.snc.household plugin is active
isHouseholdPluginActive: function() {
return gs.tableExists('csm_household_member');
},
//validates if com.snc.cs_base_extension is active
isBaseExtensionPluginActive: function() {
return gs.tableExists('sn_customer_rel_consumer_to_consumer');
},
//validates if the household field should be available in the form load
isHouseholdFieldVisible: function() {
if (!this.isHouseholdPluginActive())
return 'false';
if (gs.hasRole('admin'))
return 'true';
var consumerId = new global.CSManagementUtils().getConsumerId();
if (gs.nil(consumerId))
return 'false';
var households = new sn_csm_household.HouseHoldUtils().getCurrentHouseholdIdsForConsumerId(consumerId);
return (households.length >= 1).toString();
},
//Validates if the consumer field should be visible in the form load
isConsumerFieldVisible: function() {
if (!this.isBaseExtensionPluginActive())
return 'false';
var consumerId = new global.CSManagementUtils().getConsumerId();
if (gs.nil(consumerId) && !gs.hasRole('admin'))
return 'false';
var consumersAuthorized = [];
if (this.isBaseExtensionPluginActive()) {
consumersAuthorized = new sn_cs_base_ext.AuthorizedRepUtil().getConsumersforConsumer(consumerId);
if (consumersAuthorized.length > 1)
return 'true';
}
var consumersInHousehold = [];
if (this.isHouseholdFieldVisible() == 'true')
consumersInHousehold = new sn_csm_household.HouseHoldUtils().getConsumersforConsumer(consumerId);
return (consumersInHousehold.length > 1).toString();
},
//Validates if the consumer field should be visible when selecting a household.
isConsumerVisibleForHousehold: function() {
if (gs.hasRole('admin'))
return true;
var consumerId = new global.CSManagementUtils().getConsumerId();
if (gs.nil(consumerId))
return 'false';
var householdId = this.getParameter('sysparm_household');
var consumers = new sn_csm_household.HouseHoldUtils().getHouseholdMembersOrRepresentedConsumersInHousehold(householdId, consumerId);
return (consumers.length > 1).toString();
},
// gets the primary household for the logged in consumer to use it as default value.
getPrimaryHouseholdForLoggedInConsumer: function() {
var consumerId = new global.CSManagementUtils().getConsumerId();
return new sn_csm_household.HouseHoldUtils().getPrimaryHouseholdForConsumer(consumerId);
},
//Filter the products for consumer
getProductsForConsumer: function(consumer) {
if (gs.nil(consumer))
return null;
var gr = new GlideRecord("alm_asset");
gr.addQuery("consumer", consumer);
gr.query();
var models = ['-1'];
while (gr.next()) {
models.push(gr.getValue('model'));
}
return models;
},
//This function is used in the consumer reference qualifier to filter the consumers to display
getConsumersList: function(caseRecord) {
var consumers = [];
if (gs.nil(caseRecord))
return consumers;
if (gs.hasRole('admin')) {
if (this.isHouseholdPluginActive() && !gs.nil(caseRecord.variables.household)) {
consumers = new sn_csm_household.HouseHoldUtils().getCurrentConsumerIdsForHouseholdId(caseRecord.variables.household);
} else {
var gr = new GlideRecord("csm_consumer");
gr.query();
while (gr.next()) {
consumers.push(gr.getUniqueValue());
}
}
return consumers;
}
var consumerId = new global.CSManagementUtils().getConsumerId();
if (gs.nil(consumerId))
return consumers;
if (this.isBaseExtensionPluginActive() && (!this.isHouseholdPluginActive() || gs.nil(caseRecord.variables.household)))
consumers = new sn_cs_base_ext.AuthorizedRepUtil().getConsumersforConsumer(consumerId);
else if (this.isHouseholdPluginActive() && !gs.nil(caseRecord.variables.household)) {
consumers = new sn_csm_household.HouseHoldUtils().getHouseholdMembersOrRepresentedConsumersInHousehold(caseRecord.variables.household, consumerId);
}
if (!gs.nil(consumerId))
consumers.push(consumerId);
return consumers;
},
type: 'CSPConsumerUtils'
});
Sys ID
f056e4a30f1010103ff81b41ff767e7d