cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete a group from the collaborator's list of a Contract using a script?

Former Member
0 Kudos

Hi guys,

We have set up contracts, such that when they are created the system automatically adds a few collaborator groups by default.

We do NOT want to create a new document type for business reasons, but we want to add an extension field (checkbox) that will flag the deletion of specific groups from that collaborator's list. The script is to check that field each time it is saved and if it's checked it will delete "Group X" from that list.

I want to know if you guys think this is feasible and if it is, I have the following questions:

1) How do I access the collaborator's list for a contract?

2) How do I remove "Group X" from the Collaborators list?

I want to get ideas for actually writing the script and not so much ideas on the business logic.

Thank you,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Ok, thanks to Vikram I got the basic functionality working. I still want the system to show a confirmation pop up window before saving. How do we call a pop up confirmation window?

Here's the script as I implemented it.

confidential_check = doc.getExtensionField("confidential_check").get();

if(confidential_check){

     collaborators = doc.getCollaborators();

     if(collaborators.size() > 0){

          collabIter = collaborators.iterator();

          while (collabIter.hasNext()){

                member = collabIter.next();

                nametest = member.getDisplayName();

                if(nametest.equals("Group X")){

                     collaborators.delete(member);

                     break;

                }

          }

     }

}

0 Kudos

Hi Ivan,

Glad to hear it’s working.

Regarding popup, unfortunately, it is not supported. Using scripting you can only display hard errors on the UI. Warning message or popup is not supported. Sorry.

Regards,

Vikram

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Vikram,

Since we can't add the check as pop-up, I'm trying to minimize "accidental" deletions of security groups with the script. So I want to have 2 scenarios:

1) User checks box and saves

2) User unchecks box and saves

So for the first one, I'm pretty much done. But for the second one, I don't know how to add a Group as a collaborator. Do you have sample code line to do that?

Thanks again!

Ivan

former_member200421
Active Participant
0 Kudos

Hi Ivan,

There is an import template (Document Collaborators) that you can use to add or remove collaborators from documents if that can work for you.  I've attached example import files.  You do have to be careful to avoid adding duplicates, etc.  I always test thoroughly with a small set before updating everything I want to update.

Rosemary

Former Member
0 Kudos

Hi Ivan,

Please find the below sample script code line for adding user group in  the collaborator to MA :-

import com.sap.odp.api.usermgmt.masterdata.*;

supplierGroupHome=IBeanHomeLocator.lookup(session,GroupIBeanHomeIfc.sHOME_NAME);

                                                  // Get  value for extension field "Collaborator Groups" from the bean

                                                  supplierGroupBean = supplierGroupHome.findGroup("Supplier_safety");

                                                  groupBeanReference = supplierGroupBean.getObjectReference();

 

                                                  // Create a new member to COLLABORATORS collection

                                                  collaboratorMember = collaboratorsCollection.create();

                                                  // Set the "USER_GROUP" field value of the newly created

                                                  // member to the above obtained group bean reference

                                                  collaboratorMember.getFieldMetadata("USER_GROUP").set(collaboratorMember,groupBeanReference); //Commented

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

                                                  collaboratorRoleBean = collaboratorRoleHome.findUniqueByName("Collaborator");

                                                  if(hasValue(collaboratorRoleBean))

                                                  {

                                                            collaboratorMember.setCollaboratorRole(collaboratorRoleBean.getObjectReference());

                                                  }

                                                  collaboratorMember.setSilent(true);

                                                  // Add the collection member supplier safety group to the collaborator collection

                                                  collaboratorsCollection.add(collaboratorMember);

//end of the code to add the collaborator

Hope the above mentioned code will help you.

Thanks,

Ankur Goyal


Message was edited by: Ankur Goyal

Former Member
0 Kudos

Thanks Rosemary, we do have in place these templates. We're trying to add some functionality to a single document type based on an extended field for user clarity. I'll post the final product to give more examples to our community ....best regards,

Former Member
0 Kudos

Ankur thanks for your help, finally got the code working!!!!

Former Member
0 Kudos

Thanks a ton.I was searching for this solution a lot.

Former Member
0 Kudos

I envision this script to be like the following pseudo-code fragment:

isConfidential = getFieldValue(“Confidential”);


if(hasValue(isConfidential)) {

collabList =  doc.getCollaborators();

if (collabList.contains(“Group X”)) { doc.deleteCollab(“Group X”);}

}

0 Kudos

Hi Ivan,

You would have to first iterate through the collaborator collection.

collaborators = doc.getCollaborators();

iter = collaborators.iterator();

for (member : iter)

{

..

..

..

}

member.getPrincipal().getDisplayName() will return the name of the collaborators and collaborator group.

To delete a row in the collaborator collection, you could do something like this…

if(…) {

collaborators.delete(member);

break;

}

Hope this helps.

Regards,

Vikram