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

Got to try !


It is using the getUser Object - http://wiki.servicenow.com/index.php?title=Getting_a_User_Object


I know that gs.getUser().getLocation() you cannot dot walk - gs.getUser().getLocation().country retuns nothing



I guess you can make a filter



find_real_file.png



where the javascript is javascript:gs.getUser().getCountry();



No, didn't work on mine as we don't set a Country field on the user record, we use the one off the location



Ive learnt something new today anyway! thank you



Any other ideas to get it working?


You have to write some code and call the function in the module filter.


Its same as what Julian has posted.



Step 1: Just replace the javascript with the below:



javascript: getlocationList();



Step 2: Create a new script include with the below code in it and make sure your script include looks exactly like the image posted:



Code:


function getlocationList(){


  var user = new GlideRecord('sys_user');


  user.get(gs.getUserID());



  var ret = 'sys_idIN';



  var gr = new GlideRecord( 'cmn_location' );


  gr.addQuery( 'country', user.location.country );


  gr.query();


  while( gr.next() ){


  ret += gr.sys_id;


  }



  return ret;


}




and the Image



image.png


Thank you Ill try it later and let you know


HI Santosh



I have done this but unfortunately its not working.   I put some debugging in the script to find out the value of sys_idIN, but no value is coming back:



Background message, type:info, message: my ret value is - sys_idIN



I changed the sys_idIN to be user.sys_id and it brought back my user ID, but it still did not work.



What does the sys_idIN mean?   What value is meant to be there?



All the help is muchly appreciated



Regards