Name

sn_customerservice.CSMRelationshipService_CaseRelatedParty

Description

Implements extension point global.CSMRelationshipServiceEP Extension point for CSM Relationship framework.

Script

var CSMRelationshipService_CaseRelatedParty = Class.create();
CSMRelationshipService_CaseRelatedParty.prototype = Object.extendsObject(global.CSMRelationshipService,{
  canProcess: function(relationship) {
  	return (relationship && relationship == global.CSMRelationshipConstants.RELATIONSHIP_CASE_RELATED_PARTY);
  },
  
  getResponsibilities: function(relationship, accessLevel) {
  	var accessRoles = {};
  	var responsibilities =  global.CSMResponsibilityModelUtil.getResponsibilities(
  		relationship, accessLevel, accessRoles, this.__getAdditionalParam(global.CSMRelationshipConstants.SKIP_ROLE_CHECK)
  	);
  	// accessRoles will be used in _getEntity to check if the user has the required role
  	this.__updateContext('accessRoles', accessRoles.list);
  	return responsibilities;
  },
  
  _addPersonaCriteria: function(relationshipGR) {
  	if (gs.hasRole(global.CSMRelationshipConstants.ROLE_CONSUMER)) {
  		var loggedInConsumerId = new global.CSManagementUtils().getConsumerId();
  		relationshipGR.addQuery(global.CSMRelationshipConstants.FIELD_CONSUMER, loggedInConsumerId);
  		return;
  	}
  		
  	return global.CSMRelationshipService.prototype._addPersonaCriteria(relationshipGR);
  },
  
  _addAdditionalCriteria: function(relationshipGR) {
  	if (this.context.current && this._isChildOf(global.CSMBaseConstants.CASE_TABLE, this.context.current.getTableName())) {
  		// current refers to the case record in sn_customerservice_case table
  		relationshipGR.addQuery(global.CSMRelationshipConstants.RP_CASE_FIELD, this.context.current.sys_id);
  	}
  },

  /*
  When entity name is null, this method will return all related party entities (contact or consumer or user) added to current case record
  Format will be '<entity_type>:<entity_sys_id>'.
  entity_type for case related party can be customer_contact | csm_consumer | sys_user
  
  When entity name is not null, this method will return the value of that entity in relationShipGr
  */
  _getEntity: function(relationshipGR) {
  	if (!this.context.entityName && this.context.current && this._isChildOf(global.CSMBaseConstants.CASE_TABLE, this.context.current.getTableName())) {
  		/*
  		For case related party multiple entity types are possible: user, contact, consumer
  		As per the implemtation of CSMRelationshipServiceSNC, entity has to be string.
  		So, this method return '<entity_type>:<entity_sys_id>'
  		*/
  		if(gs.nil(relationshipGR) || gs.nil(relationshipGR.party_config) || gs.nil(relationshipGR.party_config.entity_type))
  			return '';
  		if(!this.context.accessRoles && !this.context.accessRoles.length)
  			return '';

  		var entityType = relationshipGR.party_config.entity_type;
  		var entityId = '';
  		var userId = '';
  		
  		if(entityType == global.CSMBaseConstants.CONTACT_TABLE || entityType == global.CSMBaseConstants.USER_TABLE){
  			entityId = relationshipGR.getValue(global.CSMRelationshipConstants.DEFAULT_PERSONA_FIELD);
  			userId = entityId;
  		} else if(entityType == global.CSMBaseConstants.CONSUMER_TABLE){
  			entityId = relationshipGR.getValue(global.CSMRelationshipConstants.FIELD_CONSUMER);
  			userId = new global.CSManagementUtils().getConsumerUserFromConsumer(entityId);
  		}
  					
  		if(gs.nil(userId))
  			return '';
  					
  		var gr = new GlideRecord('sys_user_has_role');
  		gr.addQuery('role.name', 'IN', this.context.accessRoles);
  		gr.addQuery('user', userId);
  		gr.query();
  		if(gr.getRowCount() == 0)
  			return '';

  		return entityType + ":" + entityId;
  	}
  	
  	// Default implementation for other conditions
  	return relationshipGR.getValue(this.context.entityName) + '';
  },

  /*
   * utility method to sync changes done to related party user records -
   * with additional users Glide List present on Case record
   * field - specifies if related party consumers or related party users need to be updated
   *
   * Only newUserId is passed -> Insert operation
   * Only oldUserId is passed -> Delete operation
   * Both are passed -> Replace operation
   */
  syncRelatedPartiesWithCase: function(caseId, newUserId, oldUserId, field) {

      this.__updatePersonaInGlideList(global.CSMBaseConstants.CASE_TABLE, caseId, field, newUserId, oldUserId);

  },

  type: 'CSMRelationshipService_CaseRelatedParty'
});

Sys ID

0c47f904eb523010bbd186de4252281a

Offical Documentation

Official Docs: