cancel
Showing results for 
Search instead for 
Did you mean: 

Update Custom CBO from BADI

pavanm26
Participant
0 Kudos

Hi Experts,

We have a requirement to update CBO based on the change in the supervising MD. We have the roles available in the Badi - Custom Checks on Project Save.

Can you please let us know if we can use this BADI to update the changes in supervising MD in CBO's. As per my understanding, we cannot use any update statements and have to use API's to update CBO's from BADI's. Please let us know the process to update the CBO's(SAP help document ) and will there be any issue in following this process.

Thanks & Regards

Pavan M

Accepted Solutions (1)

Accepted Solutions (1)

MartyMcCormick
Product and Topic Expert
Product and Topic Expert

Hi Pavan

I just tested this myself with very simplistic code and it worked. Can you confirm that you set up Communication Scenario with outbound service YY1_SERLPROJROLES configured along with associated comm arrangement where the outbound user is the comm user that is associated to the CBO comm scenario?

Here is the code I used (in my case my CS was called YY1_LOGICTEST and my outbound service YY1_EMPLOYEEINFO_CDS_REST)

* Check if outbound service exists in the communication scenario

* Replace the values for communication_scenario and outbound_service as required.

CHECK cl_ble_http_client=>is_service_available(

communication_scenario = 'YY1_LOGICTEST'

outbound_service = 'YY1_EMPLOYEEINFO_CDS_REST'

) = abap_true.

* Creation of the HTTP client to access the outbound service

* Replace the values for communication_scenario and outbound_service as required.

DATA(lo_client) = cl_ble_http_client=>create(

communication_scenario = 'YY1_LOGICTEST'

outbound_service = 'YY1_EMPLOYEEINFO_CDS_REST'

).

* we get the csrf token to be able to make the POST call later

DATA(request) = cl_ble_http_request=>create( ).

DATA lv_s2 TYPE string VALUE '/YY1_EMPLOYEEINFO_CDS/YY1_EMPLOYEEINFO?$top=1'.

request->set_header_parameter( exporting name = 'X-CSRF-TOKEN' value = 'FETCH' ).

request->set_method( 'GET' )->set_resource_extension( lv_s2 ).

TRY .

DATA(response) = lo_client->send( request ).

DATA(lv_csrf) = response->get_header_parameter( 'x-csrf-token' ).

CATCH cx_ble_http_exception INTO DATA(l5).

ENDTRY.

DATA: lv_payload TYPE string VALUE '{ "BPID": "98765", "CustomField1": "test1" }'.

DATA(request1) = cl_ble_http_request=>create( ).

DATA lv_s1 TYPE string VALUE '/YY1_EMPLOYEEINFO_CDS/YY1_EMPLOYEEINFO'.

request1->set_header_parameter( exporting name = 'x-csrf-token' value = lv_csrf ).

request1->set_content_type( 'application/json' ).

request1->set_method( 'POST' )->set_resource_extension( lv_s1 ).

request1->set_body( lv_payload ).

TRY .

DATA(response1) = lo_client->send( request1 ).

CATCH cx_ble_http_exception INTO DATA(lx1).

ENDTRY.

Thanks,

Marty

pavanm26
Participant
0 Kudos

Hi Marty,

Thanks for the quick reply.

we have tried the code but we are not getting the value in lv_csrf. in the below statement.

DATA(lv_csrf) = response->get_header_parameter( 'x-csrf-token' ).

I have attached screenshots of the communication scenario and communication arrangement that we have created.

can you please check if the setting in the communication scenario is causing the issue?

Thanks & Regards

Pavan M

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Pavan

I believe the issue is in how you are calling the CBO. You need the CBO name along with the entity:

DATA lv_s2 TYPE string VALUE '/YY1_SERLPROJROLES?$top=1'.

versus mine:

DATA lv_s2 TYPE string VALUE '/YY1_EMPLOYEEINFO_CDS/YY1_EMPLOYEEINFO?$top=1'.

Thanks,

Marty

pavanm26
Participant
0 Kudos

Thank you, Marty. It's working fine now. The issue was with the communication scenario setup as you have indicated in the earlier post.

KevinKäding
Explorer
0 Kudos

Hello pavan_km , hello marty.mccormick

I'm facing the same topic right now.

can you tell me how I need to configure the URL path in the communication scenario?

I created a custom BO with two levels ("YY1_LEVEL1" and an association "YY1_LEVEL2")

I just want to create the level 1 first.

Thank you and best regards
Kevin

Answers (2)

Answers (2)

inesmartins
Participant
0 Kudos

Hello,

Did you solve it?
I have followed the same steps as you, but i'm getting:

Exception CX_BLE_HTTP_EXCEPTION occurred in CL_BLE_HTTP_CLIENT

 

Outbound call failed with status code 403, reason: Unified Connectivity: Forbidden. [BLE_RUNTIME_SUPPORT(010)]

Can you help me?

Regards,
Ines Martins

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello

I dont think IF_CBO_WRITE is enabled on this custom logic. I think you can call the CBO via HTTPS as documented here: https://help.sap.com/viewer/0f69f8fb28ac4bf48d2b57b9637e81fa/2011.500/en-US/a8036fc167d74f4f8e13b022...

Thanks,

Marty

pavanm26
Participant
0 Kudos

Hi Marty,

the code provided in the help is working in when used in the CBO but while using in BADI it is giving error as there are write or update operations.

thanks & regards

Pavan M

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Pavan

I would need to set this up in a sandbox and test myself. You created Communication Arrangement based on your Custom Comm Scenario is that correct? Do you mind sharing your sample code?

Thanks,

Marty

pavanm26
Participant
0 Kudos

Hi Marty,

Thank you for your reply.

the following are the details:

CBO structure

EngagementProject(Project_ID) | Role(Project_Role) | SupervisignMDOldBP(Business_Partner_ID) | SupervisingMDnewBP(NewSupervisorMD)

When there is a change in the supervising MD in the customer project, the change is captured in the Custom checks on Project Save and the above CBO is to be updated with the old value and new value.

The Communication Arrangement created is Outbound Rest service without any userid or password.

The following is the code in the user exit

CHECK cl_ble_http_client=>is_service_available(

communication_scenario = 'YY1_SERLPROJROLES'

outbound_service = 'YY1_SERLPROJROLES_REST'

) = abap_true.

*Creating Communication Scenario

concatenate 'Service check successful' abap_true into data(lv_text5) separated by space.

APPEND VALUE ‎‎‎‎‎‎‎#( messagetype = 'E' messagetext = lv_text5 ) TO ct_messages.

DATA(lo_client1) = cl_ble_http_client=>create(

communication_scenario = 'YY1_SERLPROJROLES'

outbound_service = 'YY1_SERLPROJROLES_REST'

).

concatenate 'Client creation succesful' abap_true into data(lv_text6) separated by space.

APPEND VALUE #( messagetype = 'E' messagetext = lv_text6 ) TO ct_messages.

DATA(request) = cl_ble_http_request=>create( ).

concatenate 'Request creation succesful' abap_true into data(lv_text7) separated by space.

APPEND VALUE #( messagetype = 'E' messagetext = lv_text7 ) TO ct_messages.

* fetch x-csrf-token

DATA lv_s2 TYPE string VALUE '/YY1_SERLPROJROLES?$top=1'.

request->set_header_parameter( EXPORTING name = 'X-CSRF-TOKEN' value = 'FETCH' ).

request->set_header_parameter( EXPORTING name = 'Accept' value = 'application/json' ).

concatenate 'Header parameters are added' abap_true into data(lv_text8) separated by space.

APPEND VALUE #( messagetype = 'E' messagetext = lv_text8 ) TO ct_messages.

request->set_method( 'GET' )->set_resource_extension( lv_s2 ).

concatenate 'Path is added' lv_s2 into data(lv_text9) separated by space.

APPEND VALUE #( messagetype = 'E' messagetext = lv_text9 ) TO ct_messages.

TRY.

DATA(response1_2) = lo_client1->send( request ).

concatenate 'Request sent succesful' abap_true into data(lv_text10) separated by space.

APPEND VALUE #( messagetype = 'E' messagetext = lv_text10 ) TO ct_messages.

DATA(lv_csrf1_2) = response1_2->get_header_parameter( 'x-csrf-token' ).

CATCH cx_ble_http_exception INTO DATA(lx2).

ENDTRY.

IF lv_csrf1_2 IS NOT INITIAL.

DATA lv_s3p TYPE string VALUE '{"Project_ID":"'.

DATA lv_s4p TYPE string VALUE '","Project_Role":"'.

DATA lv_s5p TYPE string VALUE '","Business_Partner_ID":"'.

DATA lv_s6p TYPE string VALUE '","NewSupervisorMD":"'.

DATA lv_s7p TYPE string VALUE '"}'.

DATA lv_payloadp TYPE string.

CONCATENATE lv_s3p is_engagementproject-mp_id

lv_s4p '0SAP_RL_005'

lv_s5p lt_project_roles-businesspartner

lv_s6p ls_project_roles-businesspartner

lv_s7p INTO lv_payloadp.

DATA(request2_1) = cl_ble_http_request=>create( ).

DATA lv_s8p TYPE string VALUE '/YY1_SERLPROJROLES_CDS/YY1_SERLPROJROLES'.

request2_1->set_header_parameter( EXPORTING name = 'x-csrf-token' value = lv_csrf1_2 ).

request2_1->set_content_type( 'application/json' ).

request2_1->set_method( 'POST' )->set_resource_extension( lv_s8p ).

request2_1->set_body( lv_payloadp ).

TRY.

DATA(response2_2) = lo_client1->send( request2_1 ).

CATCH cx_ble_http_exception INTO DATA(lx3).

APPEND VALUE #( messagetype = 'E' messagetext = 'ErrorMessageText' ) TO ct_messages.

RETURN.

ENDTRY.

ENDIF.

Request you to please provide your feedback on this.

Thank you.

Regards

Pavan M