且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

更新时间:2022-09-05 23:13:36

In the last part of my blog Step by step to enable Text Collection for your custom BO I mentioned it is possible to create a web service in Cloud Application studio which contains a read operation, to return the Text Collection data to web service consumer. However the read operation can only support single BO instance ID as operation input parameter – on the other hand query operation does support multiple BO instance ID to fulfill the mass-handling requirement, however unfortunately it is not possible for query created in Cloud studio to directly return the transaction data of Text Collection. As a result we have to seek alternative.


The requirement to return text collection belonging to multiple BO instances could be achieved by C4C OData consisting of two steps.


Suppose I have two Custom BO instances JERRYORDER1 and JERRYORDER2, each has maintained their own Text Collection data:


使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

The definition of my custom BO:

使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

Here below are two necessary steps to return the Text Collection of these two BO instances via custom OData service.


(1) Create a new Custom OData Service in Work center Administrator, view OData Service Explorer, make sure you have selected Dependent object TextCollection:

使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

Get the Object ID of the two BO instances by performing fitlering against their alternative key, in my custom BO the alternative key is MainBOID.


Create a new HTTP Get request in Chrome extension Postman with url:


https:///sap/c4c/odata/cust/v1/jerrylongtextodata/MainBORootCollection?$filter=MainBOID eq ‘JERRYORDER1’ or MainBOID eq ‘JERRYORDER2’


使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

write down the Object ID of these two BO instances from response:

使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

(2) Create a HTTP post request in Postman:

使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

Paste the following text as post body. In the post body, the Object ID of two BO instances fetched from previous step are used as input parameter of two embedded HTTP GET operation contained in the batch request.

使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

Execute this post request in Postman, and the TextCollection for the two BO instances will be returned in a SINGLE roundtrip.

Response for BO JERRYORDER2:


使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

Response for BO JERRYORDER1:

使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

Note

(1) If you have too many BO instances for which you would like to query their ObjectID by alternative key for subsequent query operation, it means you have to append a lengthy string like $filter=MainBOID eq ‘JERRYORDER1’ or MainBOID eq ‘JERRYORDER2’ or …. MainBOID eq ‘JERRYORDERN’ as HTTP Get request url. It is possible that the url will exceed the maximum length of a URL for HTTP Get.


In this case you can avoid it by using HTTP Post instead:


使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

HTTP post body for doing filter operation on multiple BO instances:

使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

You will get the same result as using HTTP get with url:

使用OData服务将SAP C4C自定义BO的TextCollection暴露给外部消费者

(2) In case you need to develop a Java Program to achieve the above mentioned two steps, you can find sample code in my blog OData service parallel performance measurement – how to deal with XSRF token in Java Program and JMeter.


Further reading

You can find a list of all other blogs related to OData written by Jerry.


Consume standard C4C OData service via ABAP code

Leverage C4C Odata notification to monitor C4C Opportunity change in CRM system

OData Service backend implementation in C4C, CRM and S4 HANA

JMeter beginner – how to use JMeter to measure performance of OData service accessed parallelly

Regarding cookie manipulation in CL_HTTP_CLIENT to avoid CSRF token validation failure issue

OData service parallel performance measurement – how to deal with XSRF token in Java Program and JMeter

Expose TextCollection data belonging to a Custom BO via OData service