Show hardware asset list of logged in user on service portal using Menu Item

akashyada1
Tera Contributor

Hello all

 

I am trying to fetch the hardware asset data of logged in user on the service portal using menu item functionality but it seems not working 

kindly help/assist 

 

Please refer the below screenshot

 

akashyada1_0-1724847746069.png

 

 

Server script code - 

 

// Maximum number of entries in this Menu
var max = 100;

var t = data; // Shortcut for the data object
t.items = [];

// Get the user ID of the currently logged-in user
var u = gs.getUser().getID();

// Use record watchers to tell the header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table': 'alm_hardware', 'filter': 'active=true^assigned_to=' + u}); // Add record watcher for hardware assets

// Query for hardware assets assigned to the logged-in user
var z = new GlideRecord('alm_hardware');
z.addActiveQuery();
z.addQuery('assigned_to', u);
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();

var recordsFound = false; // To track if any records are found

while (z.next()) {
recordsFound = true; // Set flag to true if records are found
var a = {};
$sp.getRecordValues(a, z, 'display_name,model,serial_number,sys_id,sys_updated_on');

// Handle missing values
a.display_name = a.display_name || "(No display name)";
a.model = a.model || "(No model)";
a.serial_number = a.serial_number || "(No serial number)";

a.__table = z.getTableName();
a.type = 'hardware';
a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);
}

// Debug: Log whether records were found
gs.info("Records found: " + recordsFound);

// Sort items by the most recently updated and limit to max entries
t.items.sort(function(a, b) {
return b.sortOrder - a.sortOrder;
});
t.items = t.items.slice(0, max); // Only keep up to max items
t.count = t.items.length;

// Add 'View all hardware assets' link to the beginning of the items list
var link = {
title: gs.getMessage('View all hardware assets'),
type: 'link',
href: '?id=hardware_assets',
items: []
};
t.items.unshift(link); // Add the link to the top of the items list

 

 

 

using above code I am able to see just sys_updated_on info of hardware asset in portal menu dropdown for logged in user

akashyada1_0-1725380730325.png

 

 

@Ankur Bawiskar 

 

 

please assist on this 

0 REPLIES 0