cancel
Showing results for 
Search instead for 
Did you mean: 

How can we access Cost Center linked to a user via scripting?

Former Member
0 Kudos

We have a requirement to fetch the Manager User from Cost Center object linked to a user account in one scenario. For this I am trying to develop a beanshell script. But in iAPI of user account, cost center group is not exposed. But in Summary view of User Account, I can see a Reference called "COST_CENTER_GROUP" which in turn has a collection "COLLN_COST_CENTERS". This collection references "COST_CENTER" and then "MANAGER_USER" object which I am interested in fetching.

But I am not able to figure out how to access COST_CENTER_GROUP from the useraccount object. Experts please help.

Accepted Solutions (1)

Accepted Solutions (1)

former_member207877
Active Participant
0 Kudos

Hello Gayathri,

getFieldMetaData method can be used to access the standard fields from the class by using field id.

check the below code.

costCenterGroup = doc.getFieldMetadata("COST_CENTER_GROUP").get(doc);

Regards,

Raj

Former Member
0 Kudos

Thanks Rajshekhar.

getFieldMetaData returned an object of type com.sap.odp.common.db.ObjectReference with value same as the display name of the user.

So now I can get the display name of COST_CENTER_GROUP, but from this how can access the subordinate collection COLLN_COST_CENTERS?

Reference Guide shows this information for cost center group class:

    ID: 631

    Name: masterdata.CostCenterGrp

    Display Name: My Cost Centers

but there is no iAPI exposed. Please suggest how to proceed.


former_member207877
Active Participant
0 Kudos

Hello Gayathri,

Check IAPI Java docs there you can see cost center's API. 

I donno why it was not displayed in cost center class view.

Please find below image for your reference.

Regards,

Raj

Former Member
0 Kudos

Hi Raj,

Cost Center Bean iAPI is available (the same one in your image) but that is Class ID 626 masterdata.CostCenter. The reference included in UserAccount bean is that of Class ID 631 masterdata.CostCenterGrp. This Class 631 does not have iAPI exposed. It has a subordinate collection COLLN_COST_CENTERS which is a collection of objects of type masterdata.CostCenterSub (Class ID 633).  Cost Center is a class member in this class.

So from useraccount bean I need to navigate to Classes 631 -> 633 -> 626.

When I tried to print out the class name of the object I got via doc.getFieldMetadata("COST_CENTER_GROUP").get(doc), it showed com.sap.odp.common.db.ObjectReference.


Not sure how to proceed from here to get the subordinate collection and the cost center object in the first row of that collection. Please help.

- Gayathri

Former Member
0 Kudos

Finally solved the problem by introducing an extension field of type Object Reference (referring Cost Center object for which iAPI is there) directly in User Account object. Thanks to Kushagra A. from SAP for this suggestion!

Answers (0)