cancel
Showing results for 
Search instead for 
Did you mean: 

How to get data from a standar BO(Customer) in a custom BO (embedded component)

Former Member
0 Kudos

Hi SAP Community.

I have a Custom BO :    Invoices.bo

Inside this BO  i have an association to to Customer

Association ToCustomer to Customer;

I have my custom BO. embedded in the customer BO.

I need the basic data from Customer in my evento - after modify in my custom BO  "invoices"

This is what i'm trying but i'm getting no data.

Thanks a lot for your help

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ivan

Unfortunatelly I need more information about what you are doing.

How is the BO loaded or initialized in your embedded component?

For the time being, I assume that the Invoices' CustomerID is filled initially when creating the Invoices-Innstance in the Embedded Component.

In that case, your AfterModify need to look somewhat like this:


if (this.CustomerID.IsInitial()) {

     this.ToCustomer.Reset();

} else if (!this.ToCustomer.IsSet() || this.CustomerID != this.ToCustomer.ID) {

     this.ToCustomer = Customer.Retrieve(this.CustomerID);

}

Hope to help,

Ludger

--

Custom development with all4cloud.de

Former Member
0 Kudos

Hi Ludger!!

Thanks a lot for your response and time .

Well,,,, i'll try to explain what we are doing here.

We have created a custom business object called invoices.bo like this:

This BO. has to have the functionality to execute a web service to bring information from ECC using the ID Number of a client , So we already have this BO as an embedded component in the customer like this:

We also tryed with your code to get the Client ID like this:

but we dont have the anything bounded .

maybe we are missing something to bring the customer data to our custom BO. "invoices"

thanks again !

Former Member
0 Kudos

In your specific use-case, it looks like you are trying to filter/find Invoices by Customers on the UI.

Does this web service allow you to search invoices by internal ID, c4c customer UUID, or external ID?

The below design assumes that your webservice can handle searching invoices by C4C customer internal ID/ C4C customer UUID.

The design/code pattern to "join" two BOs together in code is the following

The Invoice BO will be your "Target", meaning you will bring data from a "Source" which will be the "Customer BO"

1. In your Target store some some sort of key to get the Source BO. In your case will be either the UUID or Internal ID of the customer.

var CustomerID = this.CustomerID_Z

2. Depending on the BO, sometimes you will be able to retrieve the BO by internal ID. You will always be able to retrieve a BO by UUID. Use the retrieve function to get the BO. Like you did above

var CustomerBOTemp = Customer.Retrieve(CustomerID);

***

If the BO does not allow you to Retrieve by Internal ID, then you would need to construct a query to get the customer data by Internal ID such as this, then do a for loop, and once it finds an instance then set the association and exit the loop

//query the Customer BO to get the account related data

import AP.FO.BusinessPartner.Global;


var query_account;

var account_selparam;

var account_instance;

var query_account_result;

query_account = Customer.QueryByIdentification;

account_selparam = query_account.CreateSelectionParams();

account_selparam.Add(query_account.InternalID, "I", "EQ", this.CustomerID);

query_account_result = query_account.Execute(account_selparam);

foreach (account_instance in query_account_result) {

this.ToCustomer = account_instance;

break;

}

***

3. Now that you have the CustomerBOTemp you can then access it to set whatever you need on the BO. For example, if you wanted to set your Customer association, then it would be

this.ToCustomer = CustomerBOTemp;

I am assuming you want to display the joined Customer BO data with your Custom Invoice BO, then do step 1,  2 and 3 in your after modify script.

4. Now that you have the association set, then you can display the joined data on your UI. Since step 1 stores the CustomerID as a FK on the Invoice header, then it will be a 1:1 relationship between Invoice and Customer or 1:M relationship between Customer and Invoices...

Open the UI designer create a UI (TI, OWL, QV) on top of the Invoice BO and then just drag and drop the ToCustomer UI elements directly on to the UI since it is a 1:1 relationship.

Former Member
0 Kudos

Hi Rei Kasai!!!

Thanks for you reply.

following your suggestions i did something like this:

and in my event i have this code:

But i'm still having problems with the "initial value of customer id"

and related to your suggestion:

"1. In your Target store some some sort of key to get the Source BO. In your case will be either the UUID or Internal ID of the customer."

the main question is ¿How to store the key of the source BO or from where can i take the key value? in order to have the id to execute the query and get the data from the customer.

thanks again for your valuable help.