Get full name of user from Active directory

JEytonJEyton Member Posts: 33
Hi!

How do I get the full name of the user in NAV? The USERID gives me only the users loginname and I want the full name.

Anyone have any idea?

Answers

  • idiotidiot Member Posts: 651
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • JEytonJEyton Member Posts: 33
    Hi again

    Thanks for the link.

    I tried the automation 'Windows Script Host Object Model'.WshNetwork but none of functions worked for me. I only get the login name and not the name of the user.

    The ENVIRON function (for example environ('Username') gave me only the loginname aswell.

    Is there anything I have missed?
    ](*,)
  • garakgarak Member Posts: 3,263
    message(environ('Userdomain')+'/'+environ('Username')); 
    or
    message(environ('USERDNSDOMAIN')+'/'+environ('Username'));
    

    is not enough :?:
    What do you need also :?:

    Regards
    Do you make it right, it works too!
  • JEytonJEyton Member Posts: 33
    I need the name and not the id (username) of user. For exampel the username for a user is DOMAIN\TJONES and his full name is Tom Jones.

    In the form "Windows users & groups" i want the column Name and not the ID
  • garakgarak Member Posts: 3,263
    ah ok you need to read the AD. No problem. I would post here the whole solution, but i'm at home and here is no AD to test :-( . So, lets start with theory. You must only know the DC and domain (thats no problem).

    You can solve this for example with an vbs script with return parameter. This script your call from NAV and you read the returnvalue. The other method is, let check my brain, it think it was ADO. Because since Win2000 you can fire up sql commands to the machine :-)

    so, with ADO and provider = (i hope its the true name) "ADsDSOObject"
    you can fire up "SELECT * FROM [url=LDAP://dc=YourDomainName]LDAP://dc=YourDomainName[/url] WHERE objectClass = 'user' and objectCategory = 'person' and uid = 'Angela Merkel' ".

    Also possible:
    check the automation: "Active DS Type Library"

    So, test one or both (theory) solutions.

    If you need a example, if you doesn't find the solution, lets us know.

    Regards
    Do you make it right, it works too!
  • garakgarak Member Posts: 3,263
    ah, forgotten. If you only need the Name (and not the other fields in you Ou) you can also use the table "Windows Object".

    these table contains the following coloumns:
    GUID	ID	Name	Type 	SID	Distinguished Name	
    

    If you need more / other fields, then LDAP://

    Regards.
    Do you make it right, it works too!
  • JEytonJEyton Member Posts: 33
    Hi Garak!

    Thanks for the information and the good examples.

    I am trying to get the Name from the table "windows object" but I cant get it to work. The key to the table is "GUID" and I dont have that value.

    Also when i am trying to set a filter to the table and use FIND to retrieve the value I only get error messages.
  • garakgarak Member Posts: 3,263
    WindowsObject.reset;
    WindowsObject.setfilter(ID,environ('Username'));
    if WindowsObject.findset(false) then begin
      repeat
        message(WindowsObject.Name + ' / ' + WindowsObject."Distinguished Name");
      until WindowsObject.next = 0;
    end;
    

    doesn't work?
    Do you make it right, it works too!
  • JEytonJEyton Member Posts: 33
    Thank you very much! Works like a charm...

    Kind regards!
  • garakgarak Member Posts: 3,263
    Please, you're welcome

    So, please write [Solved] infront of the subject in your first post.

    Regards
    Do you make it right, it works too!
  • DuizyDuizy Member Posts: 8
    Actual solution for OBJECT Codeunit 418 Login Management:

    PROCEDURE GetUserName@1100520000(UserID@1100520001 : Code[20]) : Text[250];
    VAR
    User@1100520003 : Record 2000000002;
    WindowsLogin@1100520004 : Record 2000000054;
    WindowsObject@1100520000 : Record 2000000050;
    BEGIN
    IF UserID <> '' THEN
    IF User.GET(UserID) THEN
    EXIT(User.Name)
    ELSE BEGIN
    WindowsLogin.SETFILTER(ID,STRSUBSTNO('@*%1',UserID));
    IF WindowsLogin.FINDFIRST THEN BEGIN
    WindowsObject.SETRANGE(SID,WindowsLogin.SID);
    IF WindowsObject.FINDFIRST THEN
    EXIT(WindowsObject.Name);
    END;
    END;
    END;
Sign In or Register to comment.