Name

sn_cs_builder.NodeGRList

Description

No description available

Script

var NodeGRList = Class.create();
NodeGRList.prototype = {
  initialize: function() {
  },
  getNodesForGoal : function(goal) {
  	var goalGR = new GlideRecordSecure("sys_cb_goal");
  	goalGR.addQuery("sys_id", goal);
  	goalGR.query();
  		
  	if (goalGR.next())
  		return this._getNodes(goal);
  },
  
  _getNodes : function(goal) {
  	var nodes = [];
  	var nodeGR = new GlideRecord("sys_cb_node");
  	nodeGR.addQuery("topic_goal", goal);
  	nodeGR.query();
  	
  	while(nodeGR.next())
  		nodes.push(this._getNodeAsJS(nodeGR));
  	
  	return nodes;
  	
  },
  
  _getNodeAsJS : function(nodeGR) {
  	//we have the base class record, get the extended version
  	var fullNode = new GlideRecord(nodeGR.getRecordClassName());
  	fullNode.get(nodeGR.getUniqueValue());
  	
  	if (fullNode)
  		return this._convertGRtoJS(fullNode);
  	else
  		return this._convertGRtoJS(nodeGR);
  },
  
  _convertGRtoJS : function(record) {
  	var jsrecord = {
  		display_value : record.getDisplayValue(),
  		sys_id : record.getUniqueValue(),
  		record : {}
  	};
  	var elements = record.getElements();
  	var that = this;
  	elements.forEach(function(element,idx,arr) {
  		if (record.isValidField(element.getName()))
  			jsrecord.record[element.getName()] = { 
  				value: record.getValue(element.getName()),
  				display_value: that._getDisplayValueSpecial(record,element.getName())
  			};
  		});
  			
  	return jsrecord;
  },
  
  _getDisplayValueSpecial : function (record, elemName) {
  	//there are special cases where the field we are getting the value for
  	//is a choice but the choice list is generated by a function in the global
  	//scope which isn't available to us. Since we don't want to generate a bunch
  	//of errors, for those cases just return the field value		
  	if (record.getRecordClassName() == "sys_cb_decision")
  		if (elemName == "variable" || elemName == "var_bool")
  			return record.getValue(elemName);
  	
  	if (record.getRecordClassName() == "sys_cb_action")
  		if (elemName == "vars")
  			return record.getValue(elemName);
  	
  	return record.getDisplayValue(elemName);
  },
  
  type: 'NodeGRList'
};

Sys ID

35f1d709b3c00300f7d1a13816a8dca3

Offical Documentation

Official Docs: