Monitoring User Creation and Login
Background
A project needs to monitor user account login and automatically update the user's on-duty status.
Implementation Steps
We can now implement this function through the following steps:
Create a new user data table with a single text field: username (name), and a dropdown field: on-duty status (dutyStatus)
Then set the dropdown option values for the on-duty status
In Table Settings >> Toolbar, add a Create Button
This section does not focus on various operations of the data table. For detailed operations, please refer to the document - Create Data Table Module
Now create a new user. This account cannot log in to the application. We need to add this user to application members and assign roles when creating the user record. The operations are as follows:
Click the edit icon on the right side of the create button to enter the create button editing page, and select Call Automation for the execution operation
Here we create user data through automation. The automation program is as follows: Open Record Creation Page -> Code Snippet (Add the user to application members and assign roles)
The code snippet is as follows:
javascriptconst formRecord = automatic.getVar("formRecord"); const systemUser = { id: formRecord.id, name: formRecord.name, userName: formRecord.name, password: formRecord.name, //Default password is username }; //Check if user exists before adding let accountId = null; const oldAccount = informat.system.getAccount(formRecord.id); if (oldAccount) { accountId = oldAccount.id; } else { // Add system account accountId = informat.system.addAccount(systemUser); } // Add to team with root directory and member role if (accountId) { informat.company.addCompanyMember(accountId, [], ["member"]); } informat.user.addUser(formRecord.id, ["admin"]);In this way, we can log in to the application with the newly created account
Create User
Login
When the user logs in to the application, how to automatically set the on-duty status to on duty. We need to use a global listener. The specific implementation is as follows:
Global Settings >> Listener >> Create Listener
Select the listening event: After User Enters Application -> Call Automation (Update User On-Duty Status)
The automation program (Update User On-Duty Status) is as follows:
The key point here is the parsing of input parameters. We click Add Parameter in the lower left corner, then scroll down, select Listener Event, and name it eventValue
You can print it out to see the data structure.
Therefore, we can obtain the logged-in user ID through the expression: ${eventValue.eventContent.user.id}, and match the records as follows:
Update Field: On-Duty Status to On Duty (onDuty)
Effect
Log in as user CJ1000
The on-duty status is automatically set to On Duty
Finally, if you want the newly created user to have application design permissions, you need to go to Application Management >> Application Design >> Select Members

