AddUserMembership/ ProfileMemberCreator.setGroupId/.setRoleId Problem


I have a problem with setting UserMembership on a "Blank" User, created on Anonymous User, with his Form Inputs.
The user and his profile is created, but not his Usermembership on his UserDetails in Portal Bonita.
This is the Groovy code:

UserCreator creator = new UserCreator(tsk2_emailStudent, tsk2_CodeStudent);
ContactDataCreator proContactDataCreator = new ContactDataCreator().setFaxNumber(tsk2_codeStudent);
final IdentityAPI identityAPI = apiAccessor.getIdentityAPI();
final User user = identityAPI.createUser(creator);
ProfileAPI orgProfileAPI = apiAccessor.getProfileAPI();
SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0,10);
searchOptionsBuilder.filter(ProfileSearchDescriptor.NAME, tsk2_emailStudent);
SearchResult<Profile> searchResultProfile = orgProfileAPI.searchProfiles(searchOptionsBuilder.done());
if (searchResultProfile.getResult().size()!=1)
                { return; }
Profile profile = searchResultProfile.getResult().get(0);
ProfileMemberCreator profileMemberCreator = new ProfileMemberCreator( profile.getId());
Group stugroup = apiAccessor.identityAPI.getGroupByPath["plataform","Students"];
Role sturole = apiAccessor.identityAPI.getRoleByName("Group");

//This is using ProfileMemberCreator, setting
apiAccessor.identityAPI.addUserMembership(tsk1_studentID, stugroup.getId(), sturole.getId());
//using UserMemberShip.

Both them are not working, anyone know how to fix this problem, help me, please.
Regards, Peter Grant


Submitted by phenant on Tue, 08/23/2016 - 21:45

Im using BonitaBPM 6.5.4. i can't migrate yet...

Submitted by Sean McP on Wed, 08/24/2016 - 00:08

To Show Code correctly use

< code >
your code
< /code >

removing the spaces to show code correctly as here:

your code

Thanks and regards

Submitted by phenant on Wed, 08/24/2016 - 18:08

Thanks sean, i hope someone knows the answer, i think is because getId() from both below are wrong.

Group stugroup = apiAccessor.identityAPI.getGroupByPath["plataform","Students"];
Role sturole = apiAccessor.identityAPI.getRoleByName("Group");

But if its the case, i dont know how get ids from Organization created in BonitaStudio. not in a Groovy code. Funny thing is BonitaBPM Engine not accusing error about erroneous parameter in setting ids() in that both methods.

1 answer

This one is the BEST answer!

We don't use getGroupByPath that way,

we do it like this and it works:

String fullOrganizationPath = "/acme/groupname/groupname";
Group groupSelected=apiAccessor.getIdentityAPI().getGroupByPath(fullOrganizationPath);

regarding the Role - I take it you mean Role Name not Group :)

I would also write it as:

Role sturole = apiAccessor.getIdentityAPI().getRoleByName("member");

Note - these commands are case sensitive so Member is not the same as member and getting it wrong will lead to notFound errors.

Hope that helps,


PS: If this answers your question, please mark as resolved by ticking the tick mark on the left of this reply.