GetUser - need only user name

255
4
Jump to solution
07-29-2021 08:59 AM
Labels (2)
LukeGilner1
New Contributor III

I'm trying to get the currently logged in username in an Arcade expression in ArcPro 2.8.  I've used the GetUser(Portal('https://www.arcgis.com')) to populate the user id, username, name, email etc. in a big long string, but I only want the username.  How can I do that?  Seems like it should be fairly straight forward.

2 Solutions

Accepted Solutions
LukeGilner1
New Contributor III

I've figured this out using a combination of GetUser, Mid, and Split functions.  The GetUser returns the long string of id, username, name, email, etc., so I used the Mid function to separate a portion of it, where the username begins.  Since our all of our users usernames are different lengths but have a "@" symbol in them, I was able to use the Split function to split it by the "@", which returns an array, so then I called to return the first part of the split array (array[0]).  I only need this first part in my data.  See below for what I entered in the calculate field tool.  I'm sure there's an easier way to do this.

var userinfo = Mid(GetUser(Portal('https://www.arcgis.com')),53,20);
var array = Split(userinfo,"@",1);
var username = array[0];
return username;

View solution in original post

Spacelord
New Contributor

I'm sure there's an easier way to do this.

I guess there is a slightly more elegant way. I searched the web for hours und struggled with my own fiddly solution until I found this video. Try this. I think it will work with every other entry in the dictionary list:

var p = Portal('https://www.arcgis.com');
var u = getUser(p);
var fullName = u.fullName;
return fullName;

View solution in original post

4 Replies
ScottLehto3
Occasional Contributor

I am wondering how to do this in C# using the Pro SDK. 

0 Kudos
LukeGilner1
New Contributor III

I've figured this out using a combination of GetUser, Mid, and Split functions.  The GetUser returns the long string of id, username, name, email, etc., so I used the Mid function to separate a portion of it, where the username begins.  Since our all of our users usernames are different lengths but have a "@" symbol in them, I was able to use the Split function to split it by the "@", which returns an array, so then I called to return the first part of the split array (array[0]).  I only need this first part in my data.  See below for what I entered in the calculate field tool.  I'm sure there's an easier way to do this.

var userinfo = Mid(GetUser(Portal('https://www.arcgis.com')),53,20);
var array = Split(userinfo,"@",1);
var username = array[0];
return username;

View solution in original post

Spacelord
New Contributor

I'm sure there's an easier way to do this.

I guess there is a slightly more elegant way. I searched the web for hours und struggled with my own fiddly solution until I found this video. Try this. I think it will work with every other entry in the dictionary list:

var p = Portal('https://www.arcgis.com');
var u = getUser(p);
var fullName = u.fullName;
return fullName;

View solution in original post

LukeGilner1
New Contributor III

YES - THANK YOU!

I knew there had to be an easier way to get the specific items from the dictionary list.  I too stumbled upon that video after hours of web searching, but it seemed like I needed to identify the specific users so it wouldn't work for me.

I modified your code slightly to grab the username, and I also still needed to use the split function because I only wanted the first part of the username.  Thanks again!  I get discouraged when I don't receive responses from the community.

var p = Portal('https://www.arcgis.com');
var u = getUser(p);
var fullusername = u.username;
var array = Split(fullusername,"@",1);
var username = array[0]
return username;

0 Kudos