User Name in Report

Hallo, I am trying to get the name of the user printing the report, in a report… there must be an easy way to do this? [?]

Hi, Declare a global variable called User and in the data type record user, then onaftergetrecord of the dataitem, put the following code. User.get(userid); then you could create a textbox and in the source expression put the following code. User.name this would give you the name. Thanks Regards Suresh.

It is not quite true, Suresh. Remember that there is also the “Windows Authentication” option where Users are not created in the “User” table but in the “Window Login” table instead. And for these Users, it is not so easy… Hans, do you actually mean the User full name? Isn’t the User ID enough, like on standard Navision reports?

Thanx Nelson and Suresh, Yes… i mean the user name… this should be on the signature on a letter, printed with a report… Actually i dont know how my customer is doing the login… so maybe it works. Even when they use the windows authentication, i could fill the user table in Navision… maybe not that clean, but certainly effective… :wink:

Just as a comment, we (as an end-customer) use Windows Authentication, but I also always create a corresponding Database User Login. You never know when the Windows Domain Controller will blow up in smoke and stop responding [:D]… at least the Users can login using the Navision User. [:)]

My customer is using windows authentication… the field USERID remains empty, how do i get the SID from the user? And Nelson… wasnt the idea of the Active Directory that there is only one instance of the user table? :wink: or did you stop trusting pc’s

I didn’t stop trusting PC’s… I never did trust them in the first place… [:D] Also, we’re on NT. About the UserName, I used this code once but for a slightly different thing. I’ll give it a try, but you’ll need to correct it a little: Variables: Name DataType Subtype Session Record Session User Record User SIDConversion Record SID - Account ID Code: GetUserName() UserName : Text[80] Session.RESET; Session.SETRANGE("My Session",TRUE); Session.FIND('-'); CASE Session."Login Type" OF Session."Login Type"::Database: BEGIN User.GET(Session."User ID"); EXIT(User.Name); END; Session."Login Type"::Windows: BEGIN SIDConversion.RESET; SIDConversion.SETCURRENTKEY(ID); SIDConversion.ID := Session."User ID"; SIDConversion.FIND; // User's SID is in "SIDConversion.SID" // how to you get the User Name from the Active Directory? // EXIT(?); END; END; Edit: I just remembered that there already exists a Codeunit that deals with the Database/Windows users problem. Try to check it, maybe the answer is there: Codeunit 418 Login Management. But Navision is also not getting the Name for Windows Users…

Hey I found a workaround to get the User Name, but only for NT, 2000 and XP operating system. When you log on the system creates a environment entry called “USERNAME”. With the following program code you can retrieve the username : Username String30; IF STRPOS(UPPERCASE(OSVERSION),‘WINDOWS_NT’) > 0 THEN BEGIN Username := ENVIRON(‘USERNAME’); END; Fred