The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
UserName
Posted: 14 Jan 08 6:06 PM
|
I know how to get the UserID for whoever is logged in, but how do I get thier actual UserName
like I have userID U6UJ9A00002U and my name is Neb Seb, How do I find the Neb Seb through code so I can insert it into a record I am trying to create once somone saves thier actions on a form.
Any help is appreciated.
Thank you,
|
|
|
|
Re: UserName
Posted: 14 Jan 08 6:22 PM
|
To get their full name:
select username from userinfo where userid = 'TheUserID'
Or their login name:
select usercode from usersecurity where userid = 'TheUserID'
-Ryan |
|
|
|
Re: UserName
Posted: 14 Jan 08 6:32 PM
|
I feel somewhat retarded asking this, but how do I assign a variable that value?
Dim tUserName = select username from userinfo where userid = 'TheUserID' ? or what?
Sorry for the question, but my head is tired and i cant figure this one out. |
|
|
|
Re: UserName
Posted: 14 Jan 08 6:42 PM
|
Create an ADO recordset and open that query. Then get the value from the ADO recordset.
Dim rs Dim sUserName Set rs = Application.GetNewConnection.Execute("select username from userinfo where userid = '" & useridvariable & "'") sUserName = rs.Fields("username").Value rs.Close Set rs = Nothing MsgBox "User name for " & useridvariable & " is " & sUserName
Make sense?
-Ryan |
|
|
|
Re: UserName
Posted: 14 Jan 08 6:51 PM
|
Yeah that makes sense.
Thank you,
Now here is another qustion.. Would this be the proper way to assign variables values?
Dim tHistoryID = application.basicfunctions.GetIDFor("HISTORY") Dim tActivityID = application.basicfunctions.GetIDFor("HISTORY") Dim tUserID = application.basicfunctions.CurrentUserID Dim tCurrentGrade = plGrade.Text
I am getting a syntax error on the =
any ideas?
|
|
|
|
Re: UserName
Posted: 14 Jan 08 6:54 PM
|
Hi Neb
I would suggest grabbing a VBScript book, it will make things much easier on you (just trying to be helpful ).
In VBScript, you cannot create a variable and assign it all on the same line like you can in VB.NET. You have to do:
Dim var var = "My value"
Make sense?
-Ryan |
|
|
|
Re: UserName
Posted: 14 Jan 08 6:57 PM
|
Yeah, I have one at home I think i'll start to bring in. Im more used to C# and VB.Net than VBScript.
Thanks for your help, it is greatly appreciated. |
|
|
|
Re: UserName
Posted: 15 Jan 08 2:35 AM
|
Originally posted by Ryan Farley
Dim var var = "My value"
|
|
One of our developers likes to do it like this:
Dim var : var = "My value"
Stephen
|
|
|
|
Re: UserName
Posted: 15 Jan 08 2:55 AM
|
Hi NebSeb, Just an observation that may make life a little easier, Rather than having to use the syntax to create an ADO connection, SLX has a simpler method:
Dim uname uname = GetField("USERNAME","USERINFO","USERID = '" & useridvariable & "'")
You can add extra conditions to this too if you want to ie: uname = GetField("USERNAME","USERINFO","USERID = (select userid from history where historyid = '" & idvariable & "')")
To do it this way, just ensure you use the include script 'System:SLX Database Support' - The include script does the DB connection anyway...
|
|
|
|
Re: UserName
Posted: 15 Jan 08 9:23 AM
|
NebSeb,
I usually access this by a SQL Function I've built. If you would like a copy of that, let me know.
Carla
|
|
|
|
Re: UserName
Posted: 15 Jan 08 10:56 AM
|
would you mind posting the function you use so I can see how you have done this? |
|
|
|
Re: UserName
Posted: 15 Jan 08 11:11 AM
|
Here ya go.
USE [YourDBName] GO
/***************************************************************** Author: Carla Tillman; Informative Graphics Corporation Use: Find the name of a SLX user Notes: This script is not for Repackaging. ******************************************************************/
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [sysdba].[fn_GetUserName] ( @UserID as VARCHAR(12) )
RETURNS VARCHAR(64)as BEGIN DECLARE @USERNAME VARCHAR(64);
SET @USERNAME = (SELECT USERNAME FROM SYSDBA.USERINFO WHERE USERID = @USERID) IF @USERNAME IS NULL BEGIN SET @USERNAME = 'USER_NOT_FOUND' END RETURN @USERNAME END
***********************************************************
To use this:
From SLX
"Select sysdba.fn_GetUserName('" & Application.BasicFunctions.CurrentUserID & "')"
From SQL
PRINTsysdba.fn_GetUserName('userID')
OR
SELECT LastName, FirstName, ContactID, sysdba.fn_GetUserName(AccountManagerID) FROM Contact WHERE LastName Like 'Smith%'
|
|
|
|
Re: UserName
Posted: 15 Jan 08 2:32 PM
|
If you are looking for the current user's name then:
Application.BasicFunctions.SystemInfoFor("Username")
will do the trick.
You can also use the Application.Users collection:
Application.Users.Item("UDEMOA00000I").Name Application.Users.Item("UDEMOA00000I").NameFL Application.Users.Item("UDEMOA00000I").NameFML
Stephen
|
|
|
|
Re: UserName
Posted: 15 Jan 08 4:15 PM
|
Originally posted by Stephen Redmond
If you are looking for the current user's name then:
Application.BasicFunctions.SystemInfoFor("Username")
will do the trick.
...
|
|
I like this one best  |
|
|
|
Re: UserName
Posted: 29 Oct 14 9:29 AM
|
Hi Carla,
I'm trying to call a SQL function from SLX and having a heck of a time getting the return value. Could you possibly expand a little more on the 'From SLX' portion of your reply? How do you get the result of your function call to a edit box for example?
thank you
|
|
|
|