Name

global.InteractionSecurityUtils

Description

No description available

Script

var InteractionSecurityUtils = Class.create();
InteractionSecurityUtils.prototype = {
  initialize: function() {
  },

  /*
   * Attempts to retrieve a scope for an interaction record
   * @param GlideRecord interactionGr the interaction record to find the scope for
   * @return sys_id of scope OR null
   */
  getScopeForInteraction: function(interactionGr) {
  	//Check extension point first for any preference from scopes
  	var extensionScope = this._getScopeForExtensions(interactionGr);
  	if (extensionScope)
  		return extensionScope;
  	//Check AWA next
  	if (GlidePluginManager.isActive('com.glide.awa')) {
  		var awaScope = this._getScopeForAwaQueue(interactionGr);
  		if (awaScope)
  			return awaScope;
  	}
  },

  /*
   * Attempts to retrieve a scope from an extension point
   */
  _getScopeForExtensions: function(interactionGr) {
  	var extensionPoints = new GlideScriptedExtensionPoint().getExtensions('global.InteractionScope');
  	for (var i = 0; i < extensionPoints.length; ++i) {
  		var point = extensionPoints[i];
  		if (point.applies(interactionGr)) {
  			var scope = point.getScopeForInteraction(interactionGr);
  			if (scope)
  				return scope;
  		}
  	}
  },

  /*
   * If there is an AWA queue related to the interaction, retrieve the queue's scope
   */
  _getScopeForAwaQueue: function(interactionGr) {
  	var grWorkItem = new GlideRecord('awa_work_item');
  	grWorkItem.addQuery('document_id', interactionGr.getUniqueValue());
  	grWorkItem.query();
  	if (grWorkItem.next() && grWorkItem.getValue('queue'))
  		return grWorkItem.queue.sys_scope;
  	return null;
  },

  getScopeForWorkspaceUrl: function (url) {

  	// Trim base url and path prefix from the front
  	var baseURL= GlideTransaction.get().getBaseURL();
  	var index = url.indexOf(baseURL);
  	if (index < 0)
  		return null;
  	var path = url.substring(index + baseURL.length());

  	var startIndex = path.indexOf('/');
  	if (startIndex >= 0)
  		path = path.substring(startIndex+1);

  	// Trim the end of the path until a UX Application can be found for the remaining path.
  	// Use the scope associated with that UX Application.
  	do {
  		var endIndex = path.lastIndexOf('/');
  		if (endIndex >= 0)
  			path = path.substring(0, endIndex);
  		var grWorkspace = new GlideRecord('sys_ux_page_registry');
  		grWorkspace.addQuery('path', path);
  		grWorkspace.query();
  		if (grWorkspace.next())
  			return grWorkspace.getValue('sys_scope');
  	} while (endIndex > 0 && path.length() > 0);

  	return null;
  },
  
  /**
   *append to the interaction an internal transcript of the chat
   */
  appendInternalTranscript: function(interaction_sysid, channelmetadata_document) {

  	var conversation = sn_connect.Conversation.get(
  		channelmetadata_document.split(':')[0],
  		channelmetadata_document.split(':')[1]
  	);
  	conversation.updateInteractionInternalTranscript(interaction_sysid+'');
  },

  /**
   * Attempt to retrieve an interaction via GlideRecordSecure
   * @param String sys_id The id of the interaction to retrieve
   * @param Boolean secure True if GlideRecordSecure should be used instead of GlideRecord
   * @return Boolean Whether the interaction can be retrieved retrievable
   */
  canGetInteraction: function(sys_id, secure) {
  	var grInteraction;
  	if (secure)
  		grInteraction = new GlideRecordSecure('interaction');
  	else
  		grInteraction = new GlideRecord('interaction');
  	return grInteraction.get(sys_id);
  },

  type: 'InteractionSecurityUtils'
};

Sys ID

ba0abce423333300fb0c949e27bf6557

Offical Documentation

Official Docs: