Service Portal Widget to dynamically build out Request Items with Tasks

Ashley
Kilo Sage

Good Evening,

Think I need a second pair of eyes on this,

So I am trying to build a widget that dynamically builds out the Request Items and Tasks associated with the Request the user is viewing in the Service Portal.

I am getting the Request Items to build out correctly but can't figure out how to associate the Tasks with the right Request Items, right now it just shows all Tasks on both Request Items.

Server Side Code:

	var request_id = $sp.getParameter('sys_id');
	var query ="request.sys_id="+request_id;

	data.sc_reqitem = getReqItem();
	function getReqItem() {
		var sc_req_Arr = [];
		var gr_req_item = new GlideRecord('sc_req_item');
		gr_req_item.addEncodedQuery(query);
		gr_req_item.query();
		while (gr_req_item.next()) {
			var sc_req_Obj = {};
			$sp.getRecordDisplayValues(sc_req_Obj, gr_req_item, 'number,sys_id,cat_item');
			sc_req_Arr.push(sc_req_Obj);
		}
		return sc_req_Arr;
	}

	data.tasks = getTasks();

	function getTasks() {
		var taskArr = [];
		var task = new GlideRecord('sc_task');
		task.addEncodedQuery(query);
		task.query();
		while (task.next()) {
			var taskObj = {};
			$sp.getRecordDisplayValues(taskObj, task, 'number,short_description,state,assignment_group,assigned_to,sys_id, request_item');			
			taskArr.push(taskObj);
		}
		return taskArr;
	}

HTML Code:

<div class="row" ng-repeat="item in data.sc_reqitem">
  <div class="panel-group">
    <div class="panel panel-primary">
      <div class="panel-heading">{{item.cat_item}}</div>
      <table class="table" ng-show="data.tasks.length > 0">
        <thead>
          <tr>
            <th>${Number}</th>
            <th>${Short Description}</th>
            <th>${Assignemnt Group}</th>
            <th>${Assigned To}</th>
            <th>${State}</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="task in data.tasks | filter: request_item">
            <td>${task.number}</td>
            <td>${task.cat_item}</td>
            <td>${task.assignment_group}</td>
            <td>${task.assigned_to}</td>
            <td>${task.state}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>

 

Current Results

find_real_file.png

Database View:

find_real_file.png

So one of the Request Items should only have 1 Task where the other Request Item will show the other 4 tasks, think I am missing something.

Any suggestions would be appropriated,

Kind Regards

Ashley 

 

 

 

1 ACCEPTED SOLUTION

Afternoon,

Finally figured it out, didn't need the sort in the end or the second ng-repeat, I just needed to use a filter as part of the first ng-repeat which was building out the rows.... thank god for that.

Kind Regards

Ashley

View solution in original post

15 REPLIES 15

I think you might have gone too far down, the widget was designed to work at the Request level i.e. in your url you should see something like this:

?id=order_status&table=sc_request&sys_id=440e851a1b250d10be0354a51a4bcb5d

Hold Ctrl on your keyboard and right click with the mouse on one of the widgets on the page, this will bring up the ServiceNow menu, go to Page in Designer and drag over the widget to add it.

find_real_file.png

Kind Regards

Ashley