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);
creator.setFirstName(tsk2_nameStudent).setLastName(tsk2_StudentLastname);
ContactDataCreator proContactDataCreator = new ContactDataCreator().setFaxNumber(tsk2_codeStudent);
creator.setProfessionalContactData(proContactDataCreator);
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 searchResultProfile = orgProfileAPI.searchProfiles(searchOptionsBuilder.done());
if (searchResultProfile.getResult().size()!=1)
{ return; }
Profile profile = searchResultProfile.getResult().get(0);
ProfileMemberCreator profileMemberCreator = new ProfileMemberCreator( profile.getId());
profileMemberCreator.setUserId(creator.getId());
Group stugroup = apiAccessor.identityAPI.getGroupByPath[“plataform”,“Students”];
Role sturole = apiAccessor.identityAPI.getRoleByName(“Group”);
/*
profileMemberCreator.setGroupId(stugroup.getId());
profileMemberCreator.setRoleId(sturole.getId());
*/
//This is using ProfileMemberCreator, setting role.id() group.id().
orgProfileAPI.createProfileMember(profileMemberCreator);
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

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 :slight_smile:

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,

regards
Seán

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

Im using BonitaBPM 6.5.4. i can’t migrate yet…

To Show Code correctly use

< code >
your code
< /code >

removing the spaces to show code correctly as here:

your code

Thanks and regards
Seán

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.