cancel
Showing results for 
Search instead for 
Did you mean: 

How to change a project collaborator Role with setCollaboratorRole

Former Member
0 Kudos

Hi,

We created a script on Life cycle event Validated on Project class to update a specific Collaborator Role when the project status is changed to specific value.

We think API method setCollaboratorRole should work for just that, but we cannot make it work. It does not throw an error and it does modify the role in the script variable (as per log traces we added) but it does not update it on the screen.

We have reviewed the scripting guide and many examples on SAP Community Network but we could only find examples with collaborator.delete and collaborator.add.

Can someone please tell me why it does not work?

Thanks, Michel

Sample code:

while(collaboratorsIterator.hasNext()){

    collaborator = collaboratorsIterator.next();

    if (!collaborator.getLockRole()){

        collaborator.setCollaboratorRole(collRoleReviewer);

}//if

}//while

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member207877
Active Participant
0 Kudos

Hello michel,

have you given collaborator role's Object reference in setCollaborator role method?

allCollaborators=doc.getCollaborators();

newCollaboratorMember=allCollaborators.create();


userHome=IBeanHomeLocator.lookup(session,NewUserAccountIBeanHomeIfc.sHOME_NAME);

userBean=userHome.findUniqueByEmail("xyz@sap.com");

userBeanRef=userBean.getObjectReference();


newCollaboratorMember.setPrincipal(userBeanRef);

roleHom=IBeanHomeLocator.lookup(session,CollaboratorRoleIBeanHomeIfc.sHOME_NAME);

roleBean=roleHom.findUniqueByName("Collaborator Role");

roleObjRef=roleBean.getObjectReference();


newCollaboratorMember.setCollaboratorRole(roleObjRef);

allCollaborators.add(newCollaboratorMember);


The above code snippet worked for me.


Regards,

Raj

Former Member
0 Kudos

Hi Raj,

Thank you for answer with your example.

Yes I have given the collaborator role's Object reference in setCollaborator. You are right, I should have written my example as "collaborator.setCollaboratorRole(collRoleObjRef);".

The problem I have is with updating the Rôle of an existing collaborator. Yes it works for me too with create and add for a new collaborator, but not for one already existing in the collection.

Can you please help me further with this?

Sample code v2:

...

collRoleBbeanH = IBeanHomeLocator.lookup(session,CollaboratorRoleIBeanHomeIfc.sHOME_NAME);

collRoleBean = collRoleBbeanH.findUniqueByName("Reviewer");

collRoleObjRef = collRoleBean.getObjectReference();

...

while(collaboratorsIterator.hasNext()){

    collaborator = collaboratorsIterator.next();

    if (!collaborator.getLockRole()){

        collaborator.setCollaboratorRole(collRoleObjRef);

}//if

}//while

Thanks,

Michel.