Can someone help me with showing my assets assigned to user on SP?

John Vo1
Tera Guru

This is what I have done so far.

1.  Created widget called My Assets.

find_real_file.png

2.  Here is my html code:

HTML:


<h4 class="panel-title">


My Assets


</h4>


<div>


<table>


<tr ng-repeat="asset in data.assets">


<td><a href ="nav_to.do?uri=alm_hardware.do?sys_id={{asset.sysid}}">{{asset.display}}"


</a></td>


</tr>


</table>


</div>

 

Server Script


(function() {


data.userID = gs.getUserID();


data.assets = [];


var gr = new GlideRecordSecure('alm_asset');


gr.addQuery('assigned_to',gs.getUserID());


gr.query();


data.recordCount=gr.getRowCount();


data.assets = [];


while (gr.next()) {


var asset = {};


asset.display = gr.display_name + '';


asset.assigned_to = gr.assigned_to.getDisplayValue();


asset.sysid = gr.sys_id + '';

 

data.assets.push(asset);


}


})();

 

3.  I went to SP and added the My Assets but nothing shows up that's assigned to me.

1 ACCEPTED SOLUTION

find_real_file.png

find_real_file.png

 

Attached XML (Widget: assets) as well for reference. In addition, make sure the the server side code is sufficed i.e. atleast an asset or two is assigned to your profile.

 

View solution in original post

35 REPLIES 35

Hi John,

 

You need to create Menu Option from Service Portals >> Portals. Then look for required portal & then look for the field Main Menu. Open the Main Menu page & then scroll to the Related list & add new entry: My Assets.

find_real_file.png

Script:

// only show 30 in header menu dropdown
var max = 30;
var t = data;
data.count = 0;
var items = data.items = [];

var u = gs.getUser().getID();
items.record_watchers = [];
items.record_watchers.push({'table':'alm_asset','filter':'assigned_to=' + u.toString()});

var z = new GlideRecord('alm_asset');
z.addQuery("assigned_to", u);
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();

while (z.next()) {
  var a = {};
  var title = z.display_name.toString() ;
  addCI(title, z.sys_id);
}

function addCI(title, query) {
	data.count++;
	var link = {};
	link.title = title;
	link.type = 'link';
	link.href='?id=index'; //redirects to homepage if required create a new page with named myassets & uncomment below & comment this one
  //link.href = '?id=myassets&table=alm_asset&view=asset_portal&sys_id=' + query;  
	items.push(link);
}

//Uncomment below to get View all Assets message on the top
//var link = {title: gs.getMessage('View all Assets'), type: 'link', href: '?id=index', items: []};
//items.unshift(link); // put 'View all Assets' first

Output:

find_real_file.png

But I can't click on the assets after adding the script.  I can see it but not click on it to open the record.

Try to click on any of your assets and it won't open it up.  How can I make that they can click on the asset and it takes them to it.

Hi John,

 

In the script look for comments. If there is a need to click you need to create a page & then add the page link as highlighted. Currently it directs to index (portal homepage)

find_real_file.png

Can you show me how to set that page up?