Friday 19 February 2016

Script Include - Get Current Logged In User

We need the details of the current user at many times. This is a very short code that helps you get the glideRecord of the row in sys_user table pertaining to the current user.

Coming straight to the code -

getCurrentUser: function()
{
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
gr.next();
return gr.user_name;
}

gs.getUserID() returns the sys_id of the record. We are using gliderecord to filter sys_user table.

That's It!! :)

Go ahead and use the code to fetch the data. Thanks :)

6 comments:

  1. Hi,can you help me to find specific user role through script include on service portal.above script is for logged in user

    ReplyDelete
  2. fantastic post, very informative. I wonder why the other specialists of this sector do not notice this. You should continue your writing. I am confident, you've a huge readers' base already! app entwickler berlin

    ReplyDelete
  3. I like the valuable information you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite certain I will learn many new stuff right here! Good luck for the next! apple kundendienst berlin

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete