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

I think its the while(gr.next()) query.



Won't it bring back a list anyway as the query is run from the filter? do I need the while?



The sys_id that is brought back is the sys_id of a location and not an asset record?   I need it just put the user.location.country into the filter don't I?


I see Santosh has just replied,


See if that works


seems a bit harsh - not meant to be


If that does not work we may need more info


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;


}