# AddUserMembership/ ProfileMemberCreator.setGroupId/.setRoleId Problem

**URL:** <https://community.ofelia.com/t/addusermembership-profilemembercreator-setgroupid-setroleid-problem/7708>\
**Category:** Q&A\
**Created:** [23 August 2016 19:04 UTC](https://community.ofelia.com/t/addusermembership-profilemembercreator-setgroupid-setroleid-problem/7708 "2016-08-23T19:04:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phenant](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@phenant](https://community.ofelia.com/u/phenant)\
**Post date:** [23 August 2016 19:04 UTC](https://community.ofelia.com/t/addusermembership-profilemembercreator-setgroupid-setroleid-problem/7708/1 "2016-08-23T19:04:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [24 August 2016 23:00 UTC](https://community.ofelia.com/t/addusermembership-profilemembercreator-setgroupid-setroleid-problem/7708/2 "2016-08-24T23:00:36Z")

</div>

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,

regards  
Seán

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

---

<div class="post-metadata">

**Author:** ![phenant](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@phenant](https://community.ofelia.com/u/phenant)\
**Post date:** [23 August 2016 19:45 UTC](https://community.ofelia.com/t/addusermembership-profilemembercreator-setgroupid-setroleid-problem/7708/3 "2016-08-23T19:45:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [23 August 2016 22:08 UTC](https://community.ofelia.com/t/addusermembership-profilemembercreator-setgroupid-setroleid-problem/7708/4 "2016-08-23T22:08:13Z")

</div>

_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

---

<div class="post-metadata">

**Author:** ![phenant](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@phenant](https://community.ofelia.com/u/phenant)\
**Post date:** [24 August 2016 16:08 UTC](https://community.ofelia.com/t/addusermembership-profilemembercreator-setgroupid-setroleid-problem/7708/5 "2016-08-24T16:08:05Z")

</div>

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.
