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.
Solved! Go to Solution.
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;
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;
I am wondering how to do this in C# using the Pro SDK.
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;
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;
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;
I just modified this code for my own professional use. It runs and returns my username in the arcade editor, but creates a null in Field Maps.
Does anyone have any ideas why this might be, or what could be done to fix the error?
Maybe post the code so we can try to help. I'm not sure what the problem would be. Are you using the correct Portal for your Field Maps? I believe it would be different than the above example if you're using Enterprise.
Ugh. Sorry to gum up the forum with a non-issue. I had changed the portal to my organization's, but had made a typo in doing so. I corrected it, and it works on and offline. Thank you for the help!
Pobodys Nerfect. Glad you figured it out.
For anyone searching how to do this, and finding this thread, you can also do the following: