Unable to use UserID in .GetUser api

Ginger_Main
New Contributor II

Update: Found out the user ID is actually supposed to be a Guid object and not a string. 

 

I have a data table which contains a list of UserId's. Currently, I need to convert those UserId's into usernames. I have been attempting to use the variations of the '.GetUser' api.

With this test, I have been unable to actually fill my variable with user info for analysis. Is there any known workarounds for this situation? I confirmed that .GetUser works with the username, just not with the UserID. 

Below is an example of my scripting, the string is of the userID I obtained by testing on a username. 

Ginger_Main_0-1709314886865.png

 

1 ACCEPTED SOLUTION

keknapp
New Contributor

Not sure this will help you, but I threw this together for an example of how you might be able to retrieve the user names given a list (or in your case a data table) of user id's.  Please note that if your user id's are all strings then you can simply use the "Guid.Parse" method to convert them accordingly.

'Create list of user id Guid's for example
Dim userGuid As List(Of String) = New List(Of String)()
userGuid.Add("73f6f9a1-0ef2-4d00-ba24-d9d8eb978992")
userGuid.Add("6f373de4-c9bf-4ec3-8b67-5c11f20b5b5e")
'Loop through the previously created userGuid list
For Each userId In userGuid
	Dim userInfo = BRApi.Security.Admin.GetUser(si, Guid.Parse((userId)))
	'Note, you need to access the user information by referencing the following ->  userInfo.User.
	'As can be seen in the following line, we can return just the name by retrieving 'userInfo.User.Name'
	If userInfo IsNot Nothing Then
		'Write message to error log showing User Name
		BRApi.ErrorLog.LogMessage(si, userInfo.User.Name.ToString())
	End If
Next

View solution in original post

1 REPLY 1

keknapp
New Contributor

Not sure this will help you, but I threw this together for an example of how you might be able to retrieve the user names given a list (or in your case a data table) of user id's.  Please note that if your user id's are all strings then you can simply use the "Guid.Parse" method to convert them accordingly.

'Create list of user id Guid's for example
Dim userGuid As List(Of String) = New List(Of String)()
userGuid.Add("73f6f9a1-0ef2-4d00-ba24-d9d8eb978992")
userGuid.Add("6f373de4-c9bf-4ec3-8b67-5c11f20b5b5e")
'Loop through the previously created userGuid list
For Each userId In userGuid
	Dim userInfo = BRApi.Security.Admin.GetUser(si, Guid.Parse((userId)))
	'Note, you need to access the user information by referencing the following ->  userInfo.User.
	'As can be seen in the following line, we can return just the name by retrieving 'userInfo.User.Name'
	If userInfo IsNot Nothing Then
		'Write message to error log showing User Name
		BRApi.ErrorLog.LogMessage(si, userInfo.User.Name.ToString())
	End If
Next