Name

global.RESTAPIDesignerCommon

Description

No description available

Script

var RESTAPIDesignerCommon = (function() {
  
  function normalizeServiceId(svcId) {
  	// all non-lowercase chars and digits to '_'
  	svcId = svcId.toLowerCase().replace(/[^a-z0-9_]/g, '_');
  	
  	// replace repeating '_' chars with a single '_'
  	svcId = svcId.replace(/_+/g, '_');
  	
  	// remove the trailing '_' if present
  	if (svcId.charAt(svcId.length-1) == '_')
  		svcId = svcId.substring(0, svcId.length-1);
  	
  	return svcId;
  }
  
  function normalizeRelativePath(templateUri) {
  	var uri = '/' + templateUri;
  	
  	// convert all non-alphanumeric and chars other than '_/{}' to '_'.
  	uri = uri.replace(/[^a-zA-Z0-9_\/\{\}]/g, '_');
  	
  	// replace repeating '_' chars with a single '_'
  	uri = uri.replace(/_+/g, '_');
  	
  	// replace repeating '/' chars with a single '/'
  	uri = uri.replace(/\/+/g, '/');
  	
  	// remove the trailing '_' or '/' chars if present
  	uri = uri.replace(/[_\/]+$/, '');
  	
  	if (0 === uri.length)
  		uri = '/';
  	
  	return uri;
  }
  
  function deleteLocalSchema(entityId) {
  	deleteMapping('sys_api_schema_local', entityId);	
  }
  
  function deleteParameterMappings(entityId) {		
  	deleteMapping('sys_api_parameter_map', entityId);
  	deleteMapping('sys_api_parameter_local', entityId);
  }
  
  function deleteContent(entityId) {		
  	deleteMapping('sys_api_content', entityId);
  }
  
  function deleteMapping(tableName, entityId) {
  	var mapping = new GlideRecord(tableName);
  	mapping.addQuery('api_entity', entityId);
  	mapping.query();
  	
  	if (mapping.getRowCount() > 0) {
  		mapping.deleteMultiple();
  	}		
  }
  
  return {
  	normalizeServiceId: normalizeServiceId,
  	normalizeRelativePath: normalizeRelativePath,
  	deleteParameterMappings: deleteParameterMappings,
  	deleteContent: deleteContent,
  	deleteLocalSchema: deleteLocalSchema
  };
})();

Sys ID

7453562bb767330070492811ee11a91a

Offical Documentation

Official Docs: