Custom User Object

Sometimes, using the default User object is enough for an app, but most of the time a custom User object is needed, which has specialized fields and does not necessarily need most of the fields existant on User (address, phone number etc etc).


In order to use a custom user object, it is necessary to create an inheritor of the platform SimpleUser object. Create an object, like you would to normally, but then specify the following :

  • ObjectName: <your_custom_name>
  • Extend of Code: SimpleUser
  • Table: m_user (it will NOT respect the syntax rule, you can ignore the warning in this case)
  • Tray Menu: no
  • add a “type” enum attribute (you can do that via using the template editor, as you’d do normally)

Custom code

Then, we add the following code to the object, To make the object really minimalistic by hiding most of SimpleUser’s fields, and automating group attribution, add and adapt the following code to your use case:

  • the package name
  • the class name
  • the group / type correspondance in the postSave
See Code
package com.simplicite.objects.Demo;

import java.util.*;
import com.simplicite.util.*;

 * Business object DemoUser
public class DemoUser extends com.simplicite.objects.System.SimpleUser {
	private static final long serialVersionUID = 1L;
	public void postLoad() {
		// hide most of the SimpleUser fields, keeping only email & login
		// hide all users that were not created throught this object
		setDefaultSearchSpec("demo_user_type is not null");

		//hide states menu
	public List<String> preValidate() {
		// set some mandatory SimpleUser fields
		setFieldValue("row_module_id", ModuleDB.getModuleId("ApplicationUsers"));
		//following does not work because usr_menu is not part of SimpleUser
		// we manage it in a postSave query to avoid adding a useless object attribute
		//setFieldValue("usr_menu", "1");
		setFieldValue("usr_active", Grant.USER_ACTIVE);
		return super.preValidate();
	public String postSave() {
		List<String> groups = new ArrayList();
			case "ADMIN":		groups.add("DEMO_ADMIN"); break;
			case "USER":		groups.add("DEMO_USER"); break;
		// meh practice... query instead of adding usr_menu attribute to objet
		getGrant().update("update m_user set usr_menu='1' where row_id="+getRowId());
		return super.postSave();
	private static void setRespList(String userId, List<String> newGroupsList){
		List<String> oldGroupsList = getRespList(userId);
		// remove old unused groups
		for(String oldGroup : oldGroupsList)
				Grant.removeResponsibility(userId, oldGroup);
		// add new missing groups
		for(String newGroup : newGroupsList)
				Grant.addResponsibility(userId, newGroup, Tool.getCurrentDate(), null, true, "ApplicationUsers");
	private static List<String> getRespList(String userId){
			return null;
		Grant g = Grant.getSystemAdmin();
		String[] groups = g.queryFirstColumn("select distinct g.grp_name from m_resp r inner join m_group as g on r.rsp_group_id=g.row_id where r.rsp_login_id="+userId);
		return groups!=null && groups.length>0 ? Arrays.asList(groups) : new ArrayList<String>();

Hiding states menu

To hide the states menu, we used setMenuStates(false); in the postLoad hook.


Password Reset

To give your user administrators the ability to manually reset a user’s password:

  • CustomUser
    • “Functions” panel > create
      • name: resetPassword
      • type: action
      • actionName > select existant > “reserPassword”