Getting User Name (DisplayName) for USERID

kine
Member Posts: 12,562
Hello all,
I am trying to solve simple task: getting Full user name (or DisplayName) for specified USERID. You know, you have USERID of person, which posted the invoice, but you want to print his name on the invoice. Under classic client, I was using table 2000000050 Windows Object to get the name. But this table is empty under RTC.
Ok, DotNet interop is here, I can use it. But, all examples I have found on internet are failing on permissions or "path not found" error, or are complicated (getting data from AD using CN etc.- I need to know the CN...). Example I have tried to use:
Failing on permissions (it seems because delegation). When used "Client Side", working, but asking for permissions to use the assemblies - impossible to use in this way.
Have somone some tip how to get the full name of the user under RTC?
I am trying to solve simple task: getting Full user name (or DisplayName) for specified USERID. You know, you have USERID of person, which posted the invoice, but you want to print his name on the invoice. Under classic client, I was using table 2000000050 Windows Object to get the name. But this table is empty under RTC.
Ok, DotNet interop is here, I can use it. But, all examples I have found on internet are failing on permissions or "path not found" error, or are complicated (getting data from AD using CN etc.- I need to know the CN...). Example I have tried to use:
Var Name DataType Subtype Length Domain Text 1000 Result Text 1000 PropCollection DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.PropertyCollection DirEntry DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.DirectoryEntry Env DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Environment ..... Domain := 'WinNT://'+Env.UserDomainName+'/'+UserIDValue; DirEntry := DirEntry.DirectoryEntry(Domain); PropCollection := DirEntry.Properties; Result := PropCollection.Item('FullName').Value;
Failing on permissions (it seems because delegation). When used "Client Side", working, but asking for permissions to use the assemblies - impossible to use in this way.
Have somone some tip how to get the full name of the user under RTC?
0
Answers
-
didn't try this, but maybe windows login (2000000054) with a calcfields of name might be a solution.0
-
No, because the name is same as ID in this table.0
-
Short time after I posted this question, my example started to work. It looks like it was problem of Kerberos, delegation to the AD and cached tickets. Solved!0
-
Why not just use the Global "User!UserID" inserted in Visual Studio. Then you get: [Domain]\[UserID]
Is this not sufficient? Also what is really the reason for us having UserID on reports?
/ClausClaus Lundstrøm | MVP | Senior Product Manager | Continia.com
I'm blogging here:http://mibuso.com/blogs/clausl and used to blog here: http://blogs.msdn.com/nav
I'm also offering RDLC Report Training, ping me if you are interested. Thanks to the 700 NAV developers that have now already been at my training. You know you can always call if you have any RDLC report issues :-)0 -
I want the User Name (DisplayName), not the User ID... like "Kamil Sacek" instead "ksacek". Of course, because we have this solved with one universal function working under classic client, I need to change this function to work on RTC too. It is not only for reports, it could be used to save the name into some table too. Many customers are using very "cryptic" logins and it is not possible to print them on reports because security reason... ;-)0
-
Change the "Windows Login".Name FlowField to the following formula:
Lookup("Windows Object".Name WHERE (SID=FIELD(SID)))0 -
I wanted to test it and when I updated the Windows Login table and created page over it, when opening the page I am getting:
Microsoft Dynamics NAV
Internal error 12 occurred in module 40. Contact your system administrator.
Page View - Test User Name must close.
OK
("Test User Name" is name of the page)
;-) and if the Windows Object is empty, it will not help (if the table will not be filled in when applying the filter, which doesn't work when opened in page directly...)0 -
Ok guess the table will only work with Classic client then.0
-
Still, not solved. I though that yes, but the solution worked only in few cases, sometime it worked, sometime it doesn't work. Sometime I am able to read the full name from AD, sometime I end with "Path not found" error or permission error. Still searching for solution how to get the Display Name (Full Name) for given login.0
-
Ok, solved... :-) Damn SPNs... again...
Name DataType Subtype Length DirectoryEntry DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.DirectoryEntry AuthType DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.AuthenticationTypes DirectorySearcher DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.DirectorySearcher SearchResultColl DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.SearchResultCollection Env DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Environment GetRTCUserName(UserIDVal : Code[20]) : Text[1000] Begin DirectoryEntry := DirectoryEntry.DirectoryEntry; DirectoryEntry.Path := 'LDAP://'+Env.UserDomainName; //small hack - taking domain from environment, could be a problem DirectorySearcher := DirectorySearcher.DirectorySearcher(DirectoryEntry); DirectorySearcher.Filter := '(SAMAccountName='+UserIDVal+')'; DirectorySearcher.PropertiesToLoad.Add('DisplayName'); SearchResultColl := DirectorySearcher.FindAll; IF ISNULL(SearchResultColl) THEN EXIT(UserIDVal); EXIT(SearchResultColl.Item(0).Properties.Item('DisplayName').Item(0)); end;
0 -
Hello Kine,
Thanks for putting this post.
I am also facing the same issue while accessing the USERNAME calculated from Classic and using it into RTC.
Classic works fine. But, RTC giving the same error that you have mentioned.
Could you please, suggest me what can be the solution to get it worked into RTC Report?
Thanks.0 -
I have stopped to use this solution, the results were unpredictable (slow, errors, etc.)
We have solved it by adding the Full name field into User Setup and letting users to fill the name here manually and we are using it in reports from there.0 -
Hi Kine,
Thanks for your below post.
I have few queries in this:
1) Is this method can easily be executed in 3 tier environment ?
2) Is there any permission issue can occur during execution?
3) If we have selected the DotNet variables as x64 then will it create any issues on 32 machine? or vice versa?
4) I think, this method is specific to RTC only. Not for Classic. Am I correct?
Please, suggest.kine wrote:Ok, solved... :-) Damn SPNs... again...Name DataType Subtype Length DirectoryEntry DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.DirectoryEntry AuthType DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.AuthenticationTypes DirectorySearcher DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.DirectorySearcher SearchResultColl DotNet 'System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.DirectoryServices.SearchResultCollection Env DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Environment GetRTCUserName(UserIDVal : Code[20]) : Text[1000] Begin DirectoryEntry := DirectoryEntry.DirectoryEntry; DirectoryEntry.Path := 'LDAP://'+Env.UserDomainName; //small hack - taking domain from environment, could be a problem DirectorySearcher := DirectorySearcher.DirectorySearcher(DirectoryEntry); DirectorySearcher.Filter := '(SAMAccountName='+UserIDVal+')'; DirectorySearcher.PropertiesToLoad.Add('DisplayName'); SearchResultColl := DirectorySearcher.FindAll; IF ISNULL(SearchResultColl) THEN EXIT(UserIDVal); EXIT(SearchResultColl.Item(0).Properties.Item('DisplayName').Item(0)); end;
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions