Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: how to create role via programming code
hi
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.
i 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.
Powered by Liferay™