cancel
Showing results for 
Search instead for 
Did you mean: 

Script:How to access Master Agreement collaborators

Former Member
0 Kudos

Hi

I am trying to catch 1st collaborator name from "master agreement collaborator list" using Java Beanshell. I am using the below mentioned code:

agreementBean = doc.getRootParentIBean();

contractHome=IBeanHomeLocator.lookup(session,ContractIBeanHomeIfc.sHOME_NAME); // get hold of current master agmt

CollaboratorCollection = agreementBean.getCollaborators(); // to get all collaborators assigned to a master agreement

collectionsize = CollaboratorCollection.size();

if(collectionsize >0){

Collectionbean= CollaboratorCollection.get(0) // Set pointer to 1st collaborator

DisplayName= Collectionbean.getDisplayName(); // Get name of 1st collaborator

I am facing error with DisplayName. is "getDIsplayName" the correct method to fetch name of the first collaborator? Where can I get list of methods for collaborator variable?

Regards

Mudit Saini

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Mudit,

I executed your script as a Master Agreement validation script and foud that the error is not in the getDisplayName() function but in this line:

contractHome=IBeanHomeLocator.lookup(session,ContractIBeanHomeIfc.sHOME_NAME);

But this should not be the case if this script is being executed for some other class (other than Master Agreement). In that case the error should be a missing import. Try importing the collaborator interface, viz.

com.frictionless.api.doc.collaboration.CollaboratorIBeanIfc

Let us know if this helps.

Thanks

Devesh

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Devesh

Thanks for your reply. You are right

. contractHome=IBeanHomeLocator.lookup(session,ContractIBeanHomeIfc.sHOME_NAME) was not working properly so I removed it and instead I used agreementBean = doc.getRootParentIBean() and the script is now working fine.

Now I am able to get the name of the first collaborator from master agreement. Next step for me is to compare this name with user account name and for the same I am using the below mentioned code:

-


import com.frictionless.api.usermgmt.masterdata.UserAccountIBeanIfc;

import com.frictionless.api.ibean.OrderedSubordinateCollectionIfc;

import com.frictionless.api.contracts.*;

import java.util.*;

import java.text.SimpleDateFormat;

import com.frictionless.api.contracts.ContractIBeanIfc;

import com.frictionless.api.ibean.OrderedSubordinateCollectionIfc;

agreementBean = doc.getRootParentIBean();

CollaboratorCollection = agreementBean.getCollaborators();

collectionsize = CollaboratorCollection.size();

if(collectionsize >0)

{

Collectionbean= CollaboratorCollection.get(0);

CollectionName= Collectionbean.getDisplayName();

}

UserHome=IBeanHomeLocator.lookup(session, com.frictionless.api.usermgmt.masterdata.UserAccountIBeanIfc.sHOME_NAME); // to get access to user account bean

UserBean=UserHome.find(CollectionName); // to find collaborator name in user account

UserName= UserBean.getDisplayName();

-


Now the problem here is it seems IBeanHomeLocator.lookup(session, com.frictionless.api.usermgmt.masterdata.UserAccountIBeanIfc.sHOME_NAME) doesn't work with user account bean.I am getting the following error:

-


Sourced file: inline evaluation of: ``import com.frictionless.api.usermgmt.masterdata.UserAccountIBeanIfc; import com. . . . '' : No static field or inner class: sHOME_NAME of interface com.frictionless.api.usermgmt.masterdata.UserAccountIBeanIfc

-


Is there any other method to get access to user account bean?

Regards

Mudit Saini

Edited by: Mudit_UCB on May 13, 2011 8:15 AM

Edited by: Mudit_UCB on May 13, 2011 8:16 AM

Edited by: Mudit_UCB on May 13, 2011 8:21 AM

Former Member
0 Kudos

Hi Mudit,

The UserAccountIfc doesn't have a home interface so your script is bound to give an error.

Also, what you are trying to achieve requires you to be a little cautious while writing your script. Some potential errors can be :

  • A collaborator need not always be an individual, it can be a group too.

  • The display name of a collaborator may not always be the username of a user. It can be of the form First Name Last Name which in most cases, is not the username.

If you are able to take care of the above scenarios, the next step to locate the current user account is as follows :


currentUser = session.getAccount();
username = currentUser.getUserName();

Don't forget the necessary imports.

Thanks

Devesh

Former Member
0 Kudos

Hi Devesh

  • A collaborator need not always be an individual, it can be a group too.

I am taking refernce of the first collaborator from the collaborator list who is always an individual in our business scenario

  • The display name of a collaborator may not always be the username of a user. It can be of the form First Name Last Name which in most cases, is not the username.

Yes you are correct, That is why instead of user name ,I am trying to get hold of a field called "Display_Name " mentioned in the user account RG or I'll concatenate FirstName and LastName of the user.

currentUser = session.getAccount(); provide access to the current session user. However to serve my purpose I need to get access to all the users and then pbly find first collaborator. Is it possible to achieve that. Plz suggest

Regards

Mudit Saini

Former Member
0 Kudos

Hi Mudit,

I am not sure if this will work but give it a try :


currentUserAccObjRef = session.getAccount().getAccountObjectReference();
userAccntList = IBeanHomeLocator.lookup(session,currentUserAccObjRef).findAll();

This should return you a java List of all the user accounts.

Let us know if this works.

Thanks

Devesh

Former Member
0 Kudos

Hi Davesh & Mudit -

You should be very careful using the "findAll" method on a home class, particularly a class that could have lots of records like User Account. In general, I would advise against using this API since you will put an unnecessary load on the system by loading all user accounts that are configured.

Rob

Former Member
0 Kudos

Dear Devesh, Rob

Thanks for your inputs! I just have one more doubt that I would like to clarify

For method cal2.add(Calendar.DATE,durationDay) works well when durationDay is an Integer value. However I have a constraint wherein I have to use decimal value instead of integer. Is there a way we can achieve that? Is there a function that can help us convert a decimal value to integer?

Kindly suggest

Regards

Mudit Saini

Former Member
0 Kudos

Mudit,

You can try floor and ceil functions available in java.lang.Math.

Thanks

Devesh

Former Member
0 Kudos

Hi

Can you help me any code which retrieves the collaborators from supplier creation page ?

Regards

Sudipta