0

I've successfully added a custom field to the User Sign-up page (create_account.jsp) by creating an expando column via Hook plugin. However, the field is not visible until I enable Guest permissions on it through the admin UI.

I need to be able to do this programmatically, through the Hook plugin. Exhaustive research leads me to believe that the following code should do the trick:

        Role guest = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST);

    ResourcePermissionLocalServiceUtil.setResourcePermissions(
            companyId, 
            ExpandoColumn.class.getName(), 
            ResourceConstants.SCOPE_INDIVIDUAL,        
            String.valueOf(expandoColumn.getColumnId()), 
            guest.getRoleId(), 
            new String[] { ActionKeys.VIEW, ActionKeys.UPDATE });

But it doesn't.

Anyone got any ideas?

  • The following helped me over the line: Role guest = RoleLocalServiceUtil.getRole(PortalUtil.getDefaultCompanyId(), RoleConstants.GUEST); String[] actionsRW = new String[] { ActionKeys.VIEW }; ResourcePermissionServiceUtil.setIndividualResourcePermissions(globalGroupId, companyId, ExpandoColumn.class.getName(), col.getColumnId()+"", guest.getRoleId(),actionsRW); – John Feeney Jun 11 '16 at 05:31
  • If you have fixed your problem by your own, share it as an answer, so that it may be helpful for others in future. – Parkash Kumar Jun 14 '16 at 06:54

1 Answers1

0

I tried same code as yours and it worked for me. In my opinion the problem is in "expandoColumn.getColumnId()". How do you retreive object ExpandoColumn? I tried with with table id and name:

ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(21806, "Menu");

For this try i retreive the table id directly from DataBase, from table "expandocolumn"