Name

sn_cs_builder.GoalList

Description

Gets the list of Tasks under a given Topic, stripping out the unnecessary info

Script

var GoalList = Class.create();
GoalList.prototype = {
  initialize: function() {
  	
  },
  
  getGoalsForTopic: function getGoalsForTopic(topic) {
  	var goals = [];
  	
  	if (!topic)
  		return goals;
  	
  	var topicGR = new GlideRecordSecure("sys_cb_topic");
  	if (!topicGR.get(topic) || !topicGR.canRead())
  		return goals;
  	
  	var goalGR = new GlideRecordSecure("sys_cb_goal");
  	goalGR.addQuery("topic", topic);
  	goalGR.query();
  	
  	while (goalGR.next())
  		goals.push(this._getGoalObject(goalGR));
  	
  	return goals;
  	
  },
  
  _getGoalObject : function _getGoalObject(goalGR) {
  	return {
  			name : goalGR.getValue("name"),
  			description : goalGR.getValue("description"),
  			title : goalGR.getValue("name"),
  			greeting : goalGR.getValue("greeting_msg"),
  			confirmation : goalGR.getValue("confirmation_msg"),
  			type : goalGR.getValue("type"),
  			topic : goalGR.getValue("topic"),
  			nodes : this.getNodeIdsForTopicGoal(goalGR.getValue("topic"), goalGR.getValue("sys_id")),
  			sys_id : goalGR.getValue("sys_id")
  		};
  },
  
  getGoal : function getGoal(goal) {
  	var goalObj = {};
  	
  	if (!goal)
  		return goalObj;
  	
  	var goalGR = new GlideRecordSecure("sys_cb_goal");
  	if (!goalGR.get(goal))
  		return goalObj;
  	
  	goalObj = this._getGoalObject(goalGR);
  	
  	return goalObj;
  },
  
  getNodeIdsForTopicGoal: function getNodeIdsForTopicGoal(topic, goal) {
  	var nodes = [];
  	
  	if (!goal)
  		return nodes;
  	
  	var goalGR = new GlideRecordSecure("sys_cb_goal");
  	goalGR.addQuery("topic", topic);
  	goalGR.addQuery("sys_id", goal);
  	goalGR.query();
  	
  	if (!goalGR.hasNext())
  		return nodes;
  	
  	var nodeGR = new GlideRecordSecure("sys_cb_node");
  	nodeGR.addQuery("topic_goal", goal);
  	nodeGR.query();
  	
  	while (nodeGR.next())
  		nodes.push(nodeGR.getValue("sys_id"));
  	
  	return nodes;
  },
  
  type: 'GoalList'
};

Sys ID

35f92b14b3233200f7d1a13816a8dc8a

Offical Documentation

Official Docs: