Simulate an instance attribute and share the value between bo and solutions
today is a great day!
I am going to solve the biggest problem in the SAP Cloud Application studio!
Raise your hands those who have never had the problem of
sharing a value between two different BOs, or between two different solutions.
Unfortunately the SAP Cloud Application studio has this limitation.
So what can we do?
We will never be able to share contents between BOs and Solutions?
Oh no guys, we will not give up so easily. We all are SAP developers and simply we don’t give up, never 🙂
This is why there is already an out of the box solution.
Just follow the steps below, and let me know if you liked it 🙂
I will be in SAP TechEd in Berlin 11-12-13 November for all the people that wants to share ideas and discuss about Cloud 4 Customer.
Ok let’s start!
– Download the solution template Attributes_sharing_bt_objects_and_solutions_V2.zip from SAP-Cloud-4-Customer—Ready-Templates/Attributes_sharing_bt_objects_and_solutions_V2.zip at master · Gh14Cc10/SAP-Cloud…
– Create a new solution “just for this feature” (you can name it ContentShareManager for example)
– Import the template in your solution as shown in the Figure 1
– Activate all the objects in the solution template (right click on the root and activate all objects)
– Now is the time to update the WebService Integration with the correct WSDL containing your solution namespace (the embedded wsdl contains MY namespace 😀 ). Take a look to Figure 2 and Figure 3
– Now activate your Brain. It is time to think a little. I embedded into the solution template a webservice consumer, named “ExternalWebServiceIntegration”. This consumer is there just for your tests, but you need to re-create this consumer on each solution where you want to use the sharing functionality.
So just create an External Web Service integration, give him the WSDL that you downloaded at point 2, and for each of these ws consumers create the associated communication scenario (A2X) and Integration arrangement (integration arrangement you need to create also for the Test consumer because it is not possible to include it in the solution template). So sorry for that.
Figure 4 – SEE THE PART HIGHLIGHTED WITH ‘1’
– Don’t worry… we reached our destination… the last step is to use the feature 🙂 . Create your test BO inside the “ContentShareManager” solution, or in one of your solutions (if you already trust me 😀 ).
Figure 7 – SEE THE PART HIGHLIGHTED WITH ‘2’
– Now you have to write the actions implementation. Yeah. I am not giving you any help for this, only two docx files with my code 😎
Generates the screens for your test BO, assign the permission of the WOC to your user, and start the debug. Et voilà!
– And don’t forget to give the right permissions to use the WS to the users you provided in the communication arrangements, and for the user that is using the functionality!
How it works
When store is pressed, a new AttributesManager instance will be created using the parameters your provided. The instance is automatically saved because the WS call is happening in a different session of the actual user session.
During the before-save event of the AttributesManager, if existing, a collection of attributes matching the provided attribute is retrieved inside the newborn instance. This is not the case because we are storing a new attribute 🙂
After that, the instance is retrieved again (using another ws call). On this instance is called the “CREATE_ATTRIBUTE” action, that save persistently the attribute in the AttributeDataCenter BO.
Finally the last ws call is performed: the AttributesManager instance is removed because is no longer useful.
When the retrieve button is pressed we have 4 steps:
Again a new AttributesManager instance will be created using the parameters your provided. The instance is automatically saved because the WS call is happening in a different session of the actual user session.
During the before-save event of the AttributesManager, if existing, a collection of attributes matching the provided attribute is retrieved inside the newborn instance. In this case, yes! The collection will contain your new created attribute.
Second call: we need to read again the instance now, because the first call was only useful for the creation. Let’s read our instance with the data 🙂
Third call: let’s delete the attribute now… we don’t need it anymore for our example.
Last call: always remember to remove the AttributesManager instance or your AttributesManager table will be full of unuseful things.