Name

global.SysList

Description

Locates the list that should be used for a table and view and parent (related list). 1. Search for this table, this view, this related list 2. Search for parents of this table, this view, this related list 3. Search for this table, this view 4. Search for parents of this table, this view 5. Search for this table, default view 6. Search for parents of this table, default view 7. Construct and return the default list

Script

gs.include("PrototypeServer");
gs.include("AbstractList");

var SysList = Class.create();

SysList.prototype = Object.extendsObject(AbstractList, {
  
  get : function() {
  	var answer = this.getList();
  	if (answer != null)
  		return answer;
  	
  	if (this.parentName != '') {
  		this.parentName = '';
  		this.relationshipID = '';
  		answer = this.getList();
  	}
  	
  	if (answer != null)
  		return answer;
  	
  	return this.defaultList();
  },
  
  defaultList : function() {
  	var list = new GlideSysList(this.tableName);
  	list.setViewName(new GlideScriptViewManager(this.view, true).getViewName());
  	var fields = list.getSuggestedFields();
  	// PRB585017: The dynamically generated list view - a list that has been accessed for the very first time - must
  	// be associated with the table's scope and not to the currently selected scope in the Application select list.
  	list.setTablePackageID();
  	list.setTableScopeID();
  	list.InsertListElements(fields);
  	list.createDefaultBaseline();
  	return this.getList();
  },
  
  getList : function() {
  	var answer = this.getSet(this.domainID, this.view, this.parentName);
  	if (answer != null)
  		return answer;
  	
  	if (this.domainID != 'global') {
  		answer = this.getSet(null, this.view, this.parentName);
  		if (answer != null)
  			return answer;
  	}
  	
  	if (this.view != this.defaultViewID) {
  		answer = this.getSet(null, this.defaultViewID, this.parentName);
  		if (answer != null)
  			return answer;
  	}
  	
  	return null;
  },
  
  getSet : function(domainID, viewID, parentName) {
  	var answer = this.getDB(this.tableName, domainID, viewID, parentName);
  	if (answer != null)
  		return answer;
  	
  	var list = this.getParents();
  	if (list == null)
  		return null;
  	
  	for (var i = 0; i < list.length; i++) {
  		if (list[i] == 'sys_metadata')
  			continue; // Special case.  Never inherit a list from abstract sys_metadata table
  		
  		answer = this.getDB(list[i], domainID, viewID, parentName);
  		if (answer != null)
  			return answer;
  	}
  	
  	return null;
  },
  
  getDB : function(tableName, domainID, viewID, parentName) {
  	var gr = new GlideRecord(this.SYS_UI_LIST);
  	gr.addNullQuery(this.SYS_USER);
  	gr.addQuery(this.NAME, tableName);
  	gr.addQuery(this.VIEW, viewID);
  	this.addParentQuery(gr);
  	this.addRelationshipQuery(gr);
  	this.domainQuery(gr, domainID);
  	if (!gr.next())
  		return null;
  	
  	return gr.sys_id.toString();
  },
  
  z : function() {
  }
  
});

Sys ID

7d8f32c3c0a8016400e609be97b96d89

Offical Documentation

Official Docs: