Name

sn_cs_queryrules.HouseholdQueryRuleUtil

Description

No description available

Script

var HouseholdQueryRuleUtil = Class.create();
HouseholdQueryRuleUtil.prototype = {
  initialize: function() {
  },
  	
  /* 
   * Return the households, user is associated with
   */
  getHouseholdsFromRelHouseholdToUser: function(){
  	var key = 'household_from_household_to_user_rel_' + gs.getUserID();
     
  	var householdFromHouseholdToUserRel = gs.getSession().getClientData(key);
      if (!gs.nil(householdFromHouseholdToUserRel))
          return householdFromHouseholdToUserRel.split(",");
  	
  	var householdIds ={};
  	
  	if (!gs.tableExists('sn_customer_rel_household_to_user')) 
  		return Object.keys(householdIds);
  	
  	var householdUserReln = new GlideRecord("sn_customer_rel_household_to_user");
  	
  	if (!householdUserReln.isValid()) 
  		return householdsIds;
  	
  	householdUserReln.addQuery("user",  gs.getUserID());
  	householdUserReln.addQuery("responsibility","8af8bbedb3730010700b4d43c6a8dca1");
  	householdUserReln.query();
  	
  	while(householdUserReln.next())
  		householdIds[householdUserReln.household.toString()] = true;
  	
  	var householdIdsArray = Object.keys(householdIds);
      if (householdIdsArray != null && householdIdsArray.length>0) {
          gs.getSession().putClientData(key, householdIdsArray.join(","));
      }

      return householdIdsArray;

  },
  
  getConsumersFromHouseholdOrHouseholdMemberRel: function() {
      var key = 'consumer_from_household_or_household_member_rel_' + gs.getUserID();
     
  	var consumerFromHouseholdOrHouseholdMemberRel = gs.getSession().getClientData(key);
      if (!gs.nil(consumerFromHouseholdOrHouseholdMemberRel))
          return consumerFromHouseholdOrHouseholdMemberRel.split(",");
  	
  	var consumers = {};
  	if (!gs.tableExists('csm_household_member')) 
  		return Object.keys(consumers);
  	
  	
  	var consumerId = new global.CSManagementUtils().getConsumerId();

      var householdsUnderConsumer = new sn_csm_household.HouseHoldUtils().getHouseholdsUnderConsumer(consumerId);

      if (householdsUnderConsumer.length > 0) {
          var hhmGR = new GlideRecord('csm_household_member');
          hhmGR.addQuery('household', 'IN', householdsUnderConsumer);
          hhmGR.query();
          while (hhmGR.next()) 
              consumers[hhmGR.getValue('consumer').toString()] = true;
      }

      var hmrGR = new GlideRecord('sn_customer_rel_household_member_relationship');
      hmrGR.addQuery('consumer', consumerId);
      hmrGR.addQuery('responsibility', 'c009bbedb3730010700b4d43c6a8dcef');
      hmrGR.query();

      while (hmrGR.next()) 
          consumers[hmrGR.getValue('related_consumer').toString()] = true;
      

  	var consumersIdsArray = Object.keys(consumers);
      if (consumersIdsArray != null && consumersIdsArray.length>0) {
          gs.getSession().putClientData(key, consumersIdsArray.join(","));
      }

      return consumersIdsArray;
  },

  getConsumersFromHouseHoldMemberRel : function() {
  	var consumers = [];
  	var consumerId = new global.CSManagementUtils().getConsumerId();
  	var hhmGR = new GlideRecord('sn_customer_rel_household_member_relationship');
  	hhmGR.addQuery('consumer', consumerId);
  	hhmGR.addQuery('responsibility', 'c009bbedb3730010700b4d43c6a8dcef');
  	hhmGR.query();
  	while(hhmGR.next()){
  		consumers.push(hhmGR.getValue('related_consumer'));
  	}
  	return consumers;
  },

  type: 'HouseholdQueryRuleUtil'
};

Sys ID

aee09ea20f2210103ff81b41ff767e22

Offical Documentation

Official Docs: