List of all assets matching the current logged in users location

pennieturner
Mega Guru

I want to create a link from left hand pane called My Assets which will show All Assets with the same location as the current logged in user.


I know from Dublin you can download and install something called Simple Separation but we are on Calgary so this won't work for us.

I think I need a business rule like the one for getMyApprovals, but, i'm struggling with the code as I only know a little Javascript

Has anyone been able to write anything like that or can help?

Thank you in advance

1 ACCEPTED SOLUTION

pennieturner
Mega Guru

I managed to get this working by using the following script include:



function getlocationList() {


  var user = new GlideRecord('sys_user');


  user.get(gs.getUserID());


  var answer = new Array();


  var i = 0;


  answer[i++] = new String(user);



  var g = new GlideRecord("cmn_location");


  g.addQuery("country", user.location.country);


  g.query();


  while( g.next())


  answer[i++] = new String(g.sys_id);


  return answer;


}


View solution in original post

19 REPLIES 19

poyntzj
Kilo Sage

Not done this, but what information do you have on the Assets that provides location ?


Is it a reference to the cmn_location table or something else ?   (such as you have an IP address and know which location is covered by a specific IP address range)


If it is cmn_location, are your user records also using the same reference field for thier location ?



Basically, once you know what field you are using in your asset and user, you can create a query to look it up.


Do not necessarily need any javascript for this depending on your answers to the location field


Hi Julian, thanks for your quick response



Yes, both the user record for location and the asset record lookup from the same table cmn_location.



How do I do this without javascript?



Thank you


Assuming you are refering to the Application Navigator on the left


you can add a new entry and it can be a filter


for example, this is our entry for My Raised Open Incidents and provides a quick link to my open incidents


find_real_file.png



on the same basis, you can create a new entry


Base it on your Asset


find_real_file.png


where the javascript reads javascript:gs.getUser().getLocation()



You can open a Background script and run this line to see the sys_id of the cmn_location for the user


gs.print(gs.getUser().getLocation());


Oh wow thats really good thank you! Yes the location brought back was the right one.



From there, am I able to dotwalk do you know as I want to bring back all the assets relating to my country so location.country?