This topic is locked
[SOLVED]

Help setting form field to users given name from SQL Query

3/21/2023 3:03:19 PM
ASPRunner.NET General questions
M
MSchell author

I have an Add form where I want to populate a field called "Observer" with the value returned by the query below (Users Given Name)

The code below echos the value to the web page correctly. How do I set the Observer field on my form equal to the value of the result from the query?

dynamic data;
dynamic rs = DB.Query("Select [EmplName] FROM [NSP].[dbo].[STD_PS_DL_ActivePositionsCSForOrgDash] Where [EmpUserID] = '" + Security.getUserName().ToString() + "'");
while(data = rs.fetchAssoc())
{

MVCFunctions.Echo(data["EmplName"]);
}

T
Tim 3/24/2023

Hello,

If you want to display the "Observer" field on the add page, then you'd do your query in the "Process record values" event of the add page and set the value.

dynamic data;
dynamic rs = DB.Query("Select [EmplName] FROM [NSP].[dbo].[STD_PS_DL_ActivePositionsCSForOrgDash] Where [EmpUserID] = '" + Security.getUserName().ToString() + "'");
while(data = rs.fetchAssoc())
{

values["Observer"]=data["EmplName"].ToString();

}

If you don't need to show the name on the Add page but just want to capture who added the record, what I usually do is add code to the "Before record added" event. Something like:

values["Observer"]=Security.getUserName().ToString();

Hope this helps.
Thanks,
Tim

M
MSchell author 3/26/2023

Thanks Tim, I'll try it

M
MSchell author 3/27/2023

Tim, that worked great, thanks for the help!