Message Boards
how to create role via programming code
how to create role via programming code
Expert Posts: 326 Join Date: 12/20/10 Recent Postshi
i just use liferay 7.3.5
i want to create many roles for init.
but i got problem
in RoleServiceUtil, i got
ClassName cm=ClassNameLocalServiceUtil.getClassName(Role.class.getName());
RoleServiceUtil.addRole(cm.getClassName(), classPK, name, titleMap, descriptionMap, type, subtype, serviceContext)
but about classPK, i know it's roleid of role_, but i cannot find createRole in RoleServiceUtil, i cannot get roleid before it be created.
or i have to give null and update from table manually?
i also try
ClassName cm = ClassNameLocalServiceUtil.getClassName(Role.class.getName());
Role role = RoleServiceUtil.addRole(cm.getClassName(), 0, name, null, null, RoleConstants.TYPE_REGULAR, null, null);
role.setClassPK(role.getRoleId());
RoleServiceUtil.updateRole(role);
but, RoleServiceUtil.updateRole doesn't support i give Role. and from api, i didn't see any mether for update classPK.
very thank you.
RE: how to create role via programming code
Expert Posts: 326 Join Date: 12/20/10 Recent Postsi try and got the answer
RoleServiceUtil.addRole(cm.getClassName(), 0, name, null, null, RoleConstants.TYPE_REGULAR, null, null);
when you put 0 as classPK, liferay will use the PKey of target table.