Getting User Name (DisplayName) for USERID

kinekine Member Posts: 12,562
edited 2013-08-01 in NAV Three Tier
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:
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?
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.

Answers

  • SogSog Member Posts: 1,023
    didn't try this, but maybe windows login (2000000054) with a calcfields of name might be a solution.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • kinekine Member Posts: 12,562
    No, because the name is same as ID in this table.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • kinekine Member Posts: 12,562
    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!
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • clauslclausl Member Posts: 455
    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?

    /Claus
    Claus 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 :-)
  • kinekine Member Posts: 12,562
    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... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DuikmeesterDuikmeester Member Posts: 308
    Change the "Windows Login".Name FlowField to the following formula:

    Lookup("Windows Object".Name WHERE (SID=FIELD(SID)))
  • kinekine Member Posts: 12,562
    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...)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DuikmeesterDuikmeester Member Posts: 308
    Ok guess the table will only work with Classic client then.
  • kinekine Member Posts: 12,562
    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.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • kinekine Member Posts: 12,562
    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;
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    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.
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
  • kinekine Member Posts: 12,562
    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.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    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;
    
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
Sign In or Register to comment.