Display list of Parent Incidents with all Child Incidents beneath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 10:06 PM - edited 07-09-2023 10:12 PM
Hello,
I have a task to create a portal widget that displays all open incidents that are assigned to a particular user with all of the child incidents related to the parent in a table view. I can output all incidents with no problem, but when I get to the child incidents, that is where I run into an issue. The object I am building appends all child incidents to each parent incident record, but I am able to see the correct parent Incidents in my list
Once I am able to display all child incidents that belong to each parent incident, I also need to create some kind of action that will show/hide the child incidents so that the view is not cluttered.
Please see the code I have below. I will also add a Prototype of what it should look like or similar too.
HTML:
<div>
<table class="table table-hover" role="grid" border="0">
<tr>
<th width="100">Number</th>
<th width="150">Short Description</th>
<th width="150">State</th>
</tr>
<tr ng-repeat="inc in c.data.incList">
<td>
{{inc.number}}<br/><br/>
<div ng-repeat="child in c.data.childIncList">
{{child.childNumber}}
</div>
</td>
<td>
{{inc.description}}<br/><br/>
<div ng-repeat="pol in c.data.childIncList">
{{child.childDescription}}
</div>
</td>
<td>
{{inc.state}}<br/><br/>
<div ng-repeat="pol in c.data.childIncList">
{{child.childState}}
</div>
</td>
</tr>
</table>
</div>
Server Script:
(function() {
var user = gs.getUser();
data.incList = [];
data.childIncList = [];
var incGr = new GlideRecord('incident');
incGr.addQuery('assigned_to', user);
incGr.query();
while(incGr.next()){
var incObj = {};
incObj.number = incGr.getDisplayValue('number');
incObj.description = incGr.getDisplayValue("short_description");
incObj.state = incGr.getDisplayValue("state");
data.incList.push(incObj);
var childIncGr = new GlideRecord('incident');
childIncGr.addQuery('parent_incident', incGr.sys_id);
childIncGr.query();
while(childIncGr.next()) {
var childIncObj = {};
childIncObj.childNumber = childIncGr.getDisplayValue('number');
childIncObj.childDescription = childIncGr.getDisplayValue("short_description");
childIncObj.childState = childIncGr.getDisplayValue("state");
data.childIncList.push(childIncObj);
}
}
})();
Prototype Example:
Anything Helps!
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 01:06 AM
Hi @mballinger
I have tried in another way and it is working. I have consider 2 table one for parent incident and other for child incident and for child incident table added one field called parent like below
HTML code in widget
<div>
<table class="table table-hover" role="grid" border="0">
<tr>
<th width="100">Number</th>
<th width="150">Short Description</th>
<th width="150">State</th>
</tr>
<tr ng-repeat="inc in c.data.incList">
<td>
{{inc.number}}<br/><br/>
<td>
{{inc.description}}<br/><br/>
</td>
<td>
{{inc.state}}<br/><br/>
</td>
</tr>
</table>
<h4>
List for Child Incident of above incident record
</h4>
<table class="table table-hover" role="grid" border="0">
<tr>
<th width="100">Number</th>
<th width="150">Short Description</th>
<th width="150">State</th>
<th width="150">Parent</th>
</tr>
<tr ng-repeat="child in c.data.childIncList">
<td>
{{child.childNumber}}<br/><br/>
<td>
{{child.childDescription}}<br/><br/>
</td>
<td>
{{child.childState}}<br/><br/>
</td>
<td>
{{child.parentValue}}<br/><br/>
</td>
</tr>
</table>
</div>
************************************************************************************************
Server script code in widget