Skip to main content
1-Visitor
April 21, 2016
Solved

Fetch user's avatar

  • April 21, 2016
  • 5 replies
  • 2853 views

I am creating Service for obtaining user's avatar:

var currentUser = Resources["CurrentSessionInfo"].GetCurrentUser();

var result = Users[currentUser].getAvatarURL();

But I am getting 500th server error code. Could you please point me out my mistake and help me fix my code.

I asked my question also on https://stackoverflow.com/questions/36771705/thingworx-fetch-users-avatar

Thanks in advance! I appreciate your help!

    Best answer by Aanjan

    Serg, sorry, I had misread your question. This does work for me -

    var currentUser = Resources["CurrentSessionInfo"].GetCurrentUser();

    var result = Users[currentUser].GetAvatarURL();

    currentUser stores Administrator, and I've set output of the service to STRING and I get the following as my result -

    /Thingworx/Users/Administrator/Avatar

    5 replies

    5-Regular Member
    April 21, 2016

    Serg, if you're fetching the current user's avatar, you can use

    var result = me.GetAvatarURL();

    srude1-VisitorAuthor
    1-Visitor
    April 21, 2016

    Aanjan, first of all thank you for your attention.

    I want avatar be dynamically return depends on who logged in.

    So I decided create HelperThing and implemented service above in this  HelperThing, if  I call me.GetAvatarURL(); - it will return me Avatar of HelperThing.

    Aanjan5-Regular MemberAnswer
    5-Regular Member
    April 21, 2016

    Serg, sorry, I had misread your question. This does work for me -

    var currentUser = Resources["CurrentSessionInfo"].GetCurrentUser();

    var result = Users[currentUser].GetAvatarURL();

    currentUser stores Administrator, and I've set output of the service to STRING and I get the following as my result -

    /Thingworx/Users/Administrator/Avatar