Skip to content

Commit 6a8fea3

Browse files
My assets - Service Portal Widget (#2030)
* Create my_assets.html * Create my_assets.css * Create my_assets_server_side.js * Create README.md
1 parent 7517a37 commit 6a8fea3

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# My Assets Widget
2+
3+
## Overview
4+
Displays assets assigned to the logged-in user in a clean, responsive table.
5+
Data is fetched from the `alm_asset` table using a secure server script.
6+
7+
## Files
8+
- **HTML** – Defines the widget layout and table structure
9+
- **Server Script** – Retrieves user-specific assets from `alm_asset`
10+
- **CSS** – Adds modern, responsive styling
11+
12+
## Features
13+
- Responsive table layout
14+
- Record count badge
15+
- Hover and gradient effects
16+
- Empty state message
17+
18+
## Usage
19+
1. Navigate to **Service Portal > Widgets** in ServiceNow.
20+
2. Create a new widget and paste the HTML, Server Script, Client Script, and CSS.
21+
3. Save the widget and add it to your desired portal page.
22+
4. The widget automatically displays assets assigned to the logged-in user.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.my-assets-widget {
2+
border-radius: 12px;
3+
box-shadow: 0 2px 10px rgba(0,0,0,0.08);
4+
overflow: hidden;
5+
}
6+
7+
.my-assets-widget .panel-heading {
8+
background: linear-gradient(90deg, #0078d4, #005fa3);
9+
color: #fff;
10+
padding: 12px 16px;
11+
font-weight: 500;
12+
}
13+
14+
.my-assets-widget .panel-heading .badge {
15+
background-color: #fff;
16+
color: #005fa3;
17+
font-weight: 600;
18+
}
19+
20+
.my-assets-widget .table {
21+
margin-bottom: 0;
22+
}
23+
24+
.my-assets-widget .table-hover tbody tr:hover {
25+
background-color: #f2f8ff;
26+
cursor: pointer;
27+
}
28+
29+
.my-assets-widget .asset-link {
30+
font-weight: 500;
31+
color: #0078d4;
32+
text-decoration: none;
33+
}
34+
35+
.my-assets-widget .asset-link:hover {
36+
text-decoration: underline;
37+
}
38+
39+
.my-assets-widget .panel-body.text-center {
40+
padding: 30px;
41+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<div class="panel panel-default my-assets-widget">
2+
<div class="panel-heading d-flex justify-content-between align-items-center">
3+
<h4 class="panel-title mb-0">
4+
<i class="fa fa-desktop text-primary"></i> My Assets
5+
</h4>
6+
<span class="badge badge-primary">{{data.recordCount}} Asset(s)</span>
7+
</div>
8+
9+
<div class="panel-body" ng-if="data.assets.length > 0">
10+
<div class="table-responsive">
11+
<table class="table table-hover table-striped">
12+
<thead class="thead-dark">
13+
<tr>
14+
<th>Asset Name</th>
15+
<th>Assigned To</th>
16+
<th>Action</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr ng-repeat="asset in data.assets">
21+
<td>
22+
<i class="fa fa-laptop text-secondary"></i>
23+
<a href="nav_to.do?uri=alm_hardware.do?sys_id={{asset.sysid}}"
24+
class="asset-link">
25+
{{asset.display}}
26+
</a>
27+
</td>
28+
<td>{{asset.assigned_to}}</td>
29+
<td>
30+
<a href="nav_to.do?uri=alm_hardware.do?sys_id={{asset.sysid}}"
31+
class="btn btn-sm btn-outline-primary">
32+
<i class="fa fa-eye"></i> View
33+
</a>
34+
</td>
35+
</tr>
36+
</tbody>
37+
</table>
38+
</div>
39+
</div>
40+
41+
<div class="panel-body text-center text-muted" ng-if="data.assets.length == 0">
42+
<i class="fa fa-info-circle fa-2x mb-2"></i>
43+
<p>No assets assigned to you.</p>
44+
</div>
45+
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(function() {
2+
data.userID = gs.getUserID();
3+
data.assets = [];
4+
5+
var gr = new GlideRecordSecure('alm_asset');
6+
gr.addQuery('assigned_to', gs.getUserID());
7+
gr.orderBy('display_name');
8+
gr.query();
9+
10+
data.recordCount = gr.getRowCount();
11+
12+
while (gr.next()) {
13+
data.assets.push({
14+
display: gr.getDisplayValue('display_name'),
15+
assigned_to: gr.getDisplayValue('assigned_to'),
16+
sysid: gr.getUniqueValue()
17+
});
18+
}
19+
})();

0 commit comments

Comments
 (0)