cancel
Showing results for 
Search instead for 
Did you mean: 

how to delete all collaborators from ma using beanshell?

Former Member
0 Kudos

hi,

i'm doing something like this:


// remove all collaborators

collaborators = doc.getCollaborators();

collabIter = collaborators.iterator();

while (collabIter.hasNext()){

    CollaboratorIBeanIfc collab = collabIter.next();

hashValue= collab.getCollaboratorType().hashCode();

try {

  if ((!((hashValue == 2) && (collab.getCollaboratorRole().getDisplayName().contains(GROUP_ROLE)))) &&

   (!((hashValue == 1) && (collab.getCollaboratorRole().getDisplayName().contains(OWNER_ROLE))))) {

      collabIter.remove();

   }

} catch(Exception e) {

        e.printStackTrace();

  log.setMethod("main");

  log.setLogMessage(e.getMessage());

  Logger.debug(log);

}  

}

i wish to delete all groups and users with a owner role when saving the master agreement.

this script is working well. i execute this code on master agreement lifecycle event "saved".

when i press the save button all collaborators are deleted, but when i press the done button they are all back in my master agreement.

i have also try to use collab.delete() instead of collabIter.remove() but the behaviour was the same...

what i'm doing wronge here?

thanks

Waldemar

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

i have exactly the same behaviour deleteing extension collections:


public void delExtensionCollection(IBeanIfc bean, String collectionName, String fieldName, String fieldValue) {

colln = bean.getExtensionCollection(collectionName);

for (iter = colln.size(); iter > 0; iter--) {

        ExtensionCollectionMemberIfc extMember = colln.get(iter-1);

  ExtensionFieldIfc extField = extMember.getExtensionField(fieldName);

  if (extField.get().getDisplayName().equals(fieldValue)) {

     colln.delete(extMember);

  }

    }

}

after the code is executed and i press save the collection is deleted. but after i press done the collection is back in master agreement...

Waldemar

former_member190023
Contributor
0 Kudos

Hello Waldemar,

I would recommend avoiding the "Saved" lifecycle script, for doing changes to the document.

This is because the script executes 'after' the document is fully saved, and changes applied from the script may not reflect in the already opened document (changes should be visible if you refresh the document, aka search for it and reopen).

If possible, try to move your code to Validate lifecycle script, after all validations are passed.

In general, scripting the Saved lifecycle should be done very carefully and for specific usages (mainly background activities like notifications, applying changes to other associated documents).

Regards,

Bogdan

kushagra_agrawal
Active Participant
0 Kudos

Hi Waldemar,

In which Scripting Context and at what Target you are wirting your extension Collection Deletion code?

If you are writing on Target Post_Save, it will not work as expected. Write your code on Validate and check.

Best,

Kushagra A

Former Member
0 Kudos

Hi bogdan,

thank you, after i moved my code to the validation lifecycle event it works correctly

By the way, what is the difference between "save" and "done" ?

Waldemar

former_member190023
Contributor
0 Kudos

Hi Waldemar:

Save:

  • Execute document save (and all associated validations/scripts)
  • Keep user screen in the document edit page (edit mode)

Done:

  • Execute document save (and all associated validations/scripts)
  • Move user screen to the previous breadcrumb (just like clicking on 'back' button)

Bogdan

Answers (1)

Answers (1)

former_member207877
Active Participant
0 Kudos

Hello Waldemar,

I guess there should be atleast one collaborator for an Master Agreement with "Owner" Collaborator role

Even while creating document security template it asks for the addition of owner role in collaborators.

Regards,

Raj

Former Member
0 Kudos

Hallo Raj,

what i wrote is obviously wrong

as you can see in the code i want to delete all other collaborators then"owner" and "owner group".

after the code is executed and the master agreement was saved there should be at lasst only two collaborators "owner" and "owner group"

sorry for missunderstanding...

Waldemar