- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 03:52 PM
This is the widget "My Request" on Service Portal.
I want to display group name that person who opened Incident belong to next to the name. (The place I want to display is red square below.)
If the person belong to multiple groups, I'd like to display all group names.
How should I make it?
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 04:32 PM
So looking at the HTML that is rendered through the following after angularjs runs:
<small class="text-muted">
<div ng-repeat="f in item.secondary_displays" class="secondary-display">
<span >INC0010019</span>
</div>
<div ng-repeat="f in item.secondary_displays" class="secondary-display">
<span >1 - High</span>
</div>
<div ng-repeat="f in item.secondary_displays" class="secondary-display">
<span >Avano Ishida</span>
</div>
<div>
<span>My Group Name</span>
</div>
</small>
What you are wanting to do is get the last two divs to be side by side rather than one above the other. There are a few ways to deal with that but I will show you a CSS only one.
// Added this class to the small html element. "<small class="text-muted secondary-wrapper">"
.secondary-wrapper {
// Use flexbox to order the elements to make it easiet to align the items
display: flex;
// Allows the elements to wrap to a new line
flex-wrap: wrap;
// Most elements should be max width so there is one on each line
div {
width: 100%;
}
// Second last and last element should share a line
div:nth-last-child(2), div:last-child {
width: unset;
}
// Add some distance between the second last and last element
div:last-child {
margin-left: 1em;
}
}
The result looks like:
Note that this will always make the second last and last lines in the small element share a line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 05:07 PM
You will need to do two things:
- Get the group data from the server
- Display it in the HTML
Getting the group data
You can add the following script to get all the given users groups. They you just need to all the function later in the script.
function GetGroupsForUser(user) {
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', user);
gr.query();
var res = [];
while (gr.next()) {
res.push(gr.getDisplayValue('group'));
}
return res;
}
// Just before the record is pushed to the req_list
record.groups = GetGroupsForUser(gr.getValue('opened_by'));
HTML Template
You can then replace the secondary display code with the following:
<small class="text-muted">
<div ng-repeat="f in item.secondary_displays" class="secondary-display">
<span >{{::f.display_value}}</span>
</div>
<!-- New code is below -->
<div>
<span>{{::item.groups.join(',')}}</span>
</div>
<!-- End new code -->
</small>
That will make it now look like:
Then you can just change the CSS a bit to put it inline as you display in your image.
Please mark as correct if this solves your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 05:10 PM
Thank you for the reply!
Where should I write the script of Getting the group data?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 05:13 PM
Put it below the other functions that are defined at the top of the server script. Try above the "// retrieve the request's" comment.
Then add the function call just above "data.request.req_list.push(record);"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 03:25 PM
I'm sorry for replying late.
I added the script but It's had error.
[HTML]
<div class="panel panel-default b">
<div class="panel-heading" >
<h2 class="panel-title">{{c.options.title}}</h2>
</div>
<div class="panels-container list-group">
<div class="list-group-item row" style="margin:0px;border-top:0px;" >
<div class="col-md-5" style="">
<div class="input-group">
</div>
</div>
<div class="col-md-3 col-xs-5" style="">
<div class="form-inline" ng-if="c.options.show_view == 'true'">
<label class="control-label hidden-xs" for="view">${View}</label>
<select ng-model="c.viewFilter" id="view" class="sc-basic-select" ng-change="c.changeView()" style="width:80%">
<option value="open" selected="true">${Open}</option>
<option value="close">${Closed}</option>
</select>
</div>
</div>
<div class="col-md-4 col-xs-7" style="">
<div class="input-group" style="width:100%">
<input ng-model="c.filterText" ng-keypress="c.checkEnter($event)"class="form-control" style="width:100%" placeholder="{{data.filterMsg}}" aria-label="{{data.filterMsg}}">
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="c.search()" title="${Search}" aria-label="${Search}">
<i class="fa fa-search"></i>
</button>
</span>
</div><!-- /input-group -->
</div>
</div>
<div ng-if="c.data.request.req_list.length == 0 && !c.filterText" class="panel-body panels-container">
${You do not have any requests}
</div>
<div ng-if="c.data.request.req_list.length == 0 && c.filterText" class="panel-body panels-container">
${Search didn't match any requests}
</div>
<div class="list-group-item row" ng-repeat="item in c.data.request.req_list | limitTo: c.data.lastLimit track by item.sys_id" style="margin:0px" >
<div class="col-xs-6 padder-l-none padder-r-none main-column">
<div class="primary-display">
<a href="?id={{::item.url.id}}&table={{::item.url.table}}&sys_id={{::item.url.sys_id}}" sn-focus="{{::item.highlight}}"> {{::item.display_field}} </a>
</div>
<small class="text-muted">
<div ng-repeat="f in item.secondary_displays" class="secondary-display">
<span >{{::f.display_value}}</span>
</div>
<!-- New code is below -->
<div>
<span>{{::item.groups.join(',')}}</span>
</div>
<!-- End new code -->
</small>
</div>
<div class="col-xs-3 padder-l-none padder-r-none state-column">
<div class="state">
<span> {{::item.state}}</span>
</div>
</div>
<div class="col-xs-3 padder-l-none padder-r-none updated-column">
<div class="updated">
<i class="fa fa-clock-o" aria-hidden="true" title="${Updated}"></i>
<sn-time-ago timestamp="::item.updated_on"/>
</div>
</div>
</div>
<div class="col-sm-12" ng-if="c.data.hasMore" style="padding:15px">
<div class="text-a-c" ng-if="c.fetching">
<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
<span class="sr-only">${Loading...}</span>
</div>
<button class="btn btn-default btn-show-more" ng-click="c.loadMore()"> ${Show More} </button>
</div>
</div>
</div>