I want my interface to show the currently logged in users for application in the text field. Can someone please help in getting the solution for this ?
Discussion posts and replies are publicly visible
Agree with Stefan there isn't really anything OOTB to satisfy your requirement here. However you may be able to utilize the Execute Stored Procedure plugin to record users interacting with the form, then display the stored data within the form itself, to show which users are logged in.
Note, the plugin's function fn!executestoredprocedure() is not designed to modify data, which is noted on the App Market page. However, I have used it to successfully to record auditing/logging type data in similar situations. I cannot speak to if the function will be modified in the future to physically prevent this. But, this example will update a login data set each time the a!textField() is interacted with. In a short time playing with it today, I was not able to get the auto-refresh to work (intended to have it update every 30 seconds, automatically), but it is refreshing correctly based on refreshOnVarChange, in which you can set any variables that users interact with.
Created on Appian 20.3, MSSQL database.
Table:
CREATE TABLE [dbo].[test_login_audit]( [id] [int] IDENTITY(1,1) NOT NULL, [user] [varchar](100) NULL, [loginTime] dateTime NULL ) ON [PRIMARY] GO
Stored Procedure, results in one row per user with the latest form interaction time:
CREATE PROCEDURE [dbo].[test_usp_login_audit] @user varchar(100), @loginTime dateTime AS BEGIN DECLARE @count int = (SELECT COUNT(*) FROM dbo.test_login_audit WHERE [user]=@user) IF @count = 0 BEGIN INSERT INTO dbo.test_login_audit ([user],loginTime) VALUES (@user,@loginTime) END ELSE BEGIN UPDATE dbo.test_login_audit set loginTime = @loginTime WHERE [user]=@user END SELECT loginTime from dbo.test_login_audit WHERE [user]=@user END GO
Interface, this will log an interaction on load and any time the Test Field is modified:
a!localVariables( local!testField, local!audit: a!refreshVariable( value: fn!executestoredprocedure( dataSourceName: "java:comp/env/jdbc/YOUR_DB_CONNECTION", procedureName: "dbo.test_usp_login_audit", inputs: { {name: "user", value: tostring(fn!loggedInUser())}, {name: "loginTime", value: now()} } ), /*refreshInterval: 0.5,*/ /*refreshAlways: true,*/ refreshOnVarChange: local!testField ), { a!textField( label: "Audit Result", value: local!audit, readOnly: true ), a!textField( label: "Test Field", value: local!testField, saveInto: local!testField ) } )