- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 02:29 PM
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
Database View:
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2020 10:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 04:15 AM
Hi Ashley,
I noticed you are using the same query twice for both RITM and SC_TASK.
Please define a second query for sc_task query:
request_item.request.sys_id
Thanks,
Enrique
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 05:14 AM
Hi Enrique,
Thank you for the reply,
I know, doing it the way you mentioned will simply return the same results.
Need to figure out to sort the results so they show in the correct Request Item.
Kind Regards
Ashley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 05:43 AM
Afternoon,
So I have added a sort which is now breaking the array by request_item:
var sorted = {};
for(var i = 0, max = data.tasks.length; i < max ; i++ ){
if(sorted[data.tasks[i].request_item] == undefined ){
sorted[data.tasks[i].request_item] = [];
}
sorted[data.tasks[i].request_item].push(data.tasks[i]);
}
Results:
Not sure how to use it tho with an ng-repeat...
Kind Regards
Ashley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2020 09:18 AM
Afternoon,
I think I need to use 2x ng-repeats to go down through the levels of the array, no luck so far.
Ashley