Cloud for Customer – How to bind EC to a standard screen without using context binding or outports
Probably you know that, in order to pass parameters from a screen to an embedded component, you need to bind your EC context to the main component context, or you need to use an outport containing one or more parameters, from the main component to the EC.
If you are working with a completely custom main component, these kinds of binding are possible, but try to imagine the situation in wich the main component is a standard screen (for example the QC component of an ActivityTask).
This standard component have no outports, and cause it is a standard screen you are not able to bind the EC context with the main component context.
So… have you to give up?
Look at the following procedure, proposed by me, and already approved by SAP Cloud for Customer Development Team!
Requirement: create an embedded component that can take the existing instance of an object without the need of context mapping and outport parameters.
Idea: when the object (in this example a task) is created or modified, we want to save the instance UUID (that it is not already saved in the persistence layer) in a custom business object, without the need to save it, and then, using the retrieve function as a transformation field in the embedded component (EC), we get the task UUID and we read the existing instance using the retrieve function.
- A UI can have only one Business Object mapped on the context.
- A query cannot be used because we can’t save the custom instances.
- It is not possible to save an identifier in a custom field of the task in order to get the BO with a retrieve in the UI because the retrieve doesn’t support custom fields.
- It is not possible to duplicate the standard screen in the embedded component by creating a new instance in the EC and deleting the original instance, because some event handler of the main component work on the original instance (i.e. save and complete).
Create a business object extension for the ActivityTask standard BO with a dummy field (almost a field is required).
Implement the Event-AfterModify.absl in order to save the task UUID by using a reuse function called WRITE_TASK (to be created in the step 4).
Create a custom BO that will handle the association USERUUID (unique key) to TASKUUID.
Create the Reuse Library with two functions: READ_TASK and WRITE_TASK.
The WRITE_TASK function check for existing instances with the key userUUID equal to the current userUUID. If the instance exists, it will update the taskUUID with the importing parameter, otherwise it will create a new instance.
The READ_TASK function check for existing instances with the key userUUID equal to the current userUUID. If the instance exists it return the associated taskUUID.
Create the Embedded Component with an hidden field TaskUUID binded with the /Root/DataField context node.
You can also add some other fields binded to the context attributes related to the task (see next step). In this example I added task name and task category.
Bind the Root note to the ActivityTask standard BO and add some fields if you want (see step 5). No initialize event handler is required.
Add a new field DataField to the context and set property “Is Dedicated Field” to TRUE (1).
Select a new Transformation Field and choose the READ_TASK function from the custom reuse library (see step 4) (2).
Add an event handler to the event OnValueChanged of this field (3).
Bind the Root element (4).
Check the created Field Transformation (automatically generated).
Create the BOOperation for the event handler using the read (retrieve) operation and add the NavKey parameter as nodeId, binded with the DataField (that will contain the taskUUID).
So when the EC is initialized, the field transformation start, the task UUID is filled, andthe event handler is loaded because of the DataField modification.
Add the EC to the standard QC component (no bindings are required).
You are ready to test!
Open a new task and check that the EC has the same values of the standard component. Try to change some value (and press enter because standard fields have no event handler associated) in order to see the new values also in the EC.
If you want that, by changing the category dropdown, the dependant dropdown automatically changes (withouth the need to press the enter), you have to hide the standard field and let the user to use the replicated field in the EC.