I want o display the logged-in user assets in portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 06:39 AM
Hi Team,
I have computer table and we have maintain the all users assets. we have identified the based on "assigned to".
I want to display the logged in user assets.
how to display the assets in portal.
Could you please provide the steps.
Regards,
Tharun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2025 02:40 AM
Hi @Tharun13 ,
I implemented it by creating a new widget on the asset table (alm_asset) and adding it to the portal page. If you have an asset tag and clicking on that asset tag redirects to the record of the asset. The result is shown in the below screenshot:
You can implement this on your computer table.
HTML Script:
<div class="asset-widget">
<h3>Your Assigned Assets</h3>
<div ng-if="assets.length > 0" class="asset-list">
<div ng-repeat="asset in assets" class="asset-item">
<div>
<strong>Asset Tag:</strong>
<span ng-if="asset.asset_tag !== 'N/A'">
<a href="/alm_asset.do?sys_id={{ asset.sys_id }}" target="_blank">
{{ asset.asset_tag }}
</a>
</span>
<span ng-if="asset.asset_tag === 'N/A'">
{{ asset.asset_tag }}
</span>
</div>
<div>
<strong>Asset Name:</strong> {{ asset.asset_name }}
</div>
</div>
</div>
<div ng-if="assets.length === 0" class="no-assets">
<p>No assets found.</p>
</div>
</div>
CSS:
.asset-widget {
font-family: Arial, sans-serif;
padding: 15px;
background-color: #f9f9f9;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.asset-widget h3 {
font-size: 18px;
color: #333;
margin-bottom: 10px;
}
.asset-list {
margin-top: 10px;
}
.asset-item {
padding: 10px;
border-bottom: 1px solid #ddd;
margin-bottom: 10px;
}
.asset-item:last-child {
border-bottom: none;
}
.no-assets {
color: #888;
font-size: 14px;
}
.asset-widget a {
color: #007bff;
text-decoration: none;
}
.asset-widget a:hover {
text-decoration: underline;
}
Server Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2025 03:30 AM
you can have your own widget and add it to portal page.
It will show assets assigned to logged in user
HTML:
<div>
<h2>Your Assets</h2>
<ul>
<li ng-repeat="asset in c.data.assets">
{{asset.name}} - {{asset.serial_number}}
</li>
</ul>
</div>
Client Controller:
(function() {
var c = this;
c.data.assets = [];
// Fetch the logged-in user's assets
var gr = new GlideRecord('alm_asset');
gr.addQuery('assigned_to', gs.getUserID());
gr.query();
while (gr.next()) {
c.data.assets.push({
name: gr.getValue('name'),
serial_number: gr.getValue('serial_number')
});
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader