cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP RAP - How to refresh the list of childrens after an root action has created a new child

hannemac
Participant
0 Kudos

I have a root-child data model (User-\_ChangeRequest), where childrens can be created through an action from the object page of the root entity.

I tried many scenarios already, but in no one of these the list of child nodes gets reloaded, after the action has created a new child:

action with result [1] $self

 

 

define behavior for Z_R_User alias User
{
...
  action ( features:instance ) createChangeRequest result [1] $self;
...
}

 

 

Filling the result parameter from the action

 

 

READ ENTITIES OF Z_R_User IN LOCAL MODE
     ENTITY User
     ALL FIELDS
     WITH VALUE #( FOR mapped_request IN mapped-changerequest
                 ( %tky = CORRESPONDING #( mapped_request-%tky ) ) )
     RESULT DATA(update_result).

result = VALUE #( FOR user IN update_result
                  ( %tky   = CORRESPONDING #( user-%tky )
                    %param = user ) ).

 

 

 action with result [1] entity Z_R_ChangeRequest

 

 

define behavior for Z_R_User alias User
{
...
  action ( features : instance ) createChangeRequest result [1] entity Z_R_ChangeRequest;
...
}

 

 

 Filling the result parameter from the action

 

 

READ ENTITIES OF Z_R_User IN LOCAL MODE         
     ENTITY ChangeRequest                                    
     ALL FIELDS                                              
     WITH VALUE #( FOR mapped_request IN mapped-changerequest
                   ( %tky = mapped_request-%tky ) )          
     RESULT DATA(update_result).                             
                                                             
result = VALUE #( FOR request IN update_result               
                  ( %tky   = CORRESPONDING #( request-%tky ) 
                    %param = request ) ).                    

 

 

 

factory action 

 

 

define behavior for Z_R_User alias User
{
...
  factory action ( features : instance ) createChangeRequest [1];
...
}

 

 

 I had to fill the table user in the changing parameter mapped manually, because if not the following error appears:

hannemac_0-1709550497843.png

 

 

 

LOOP AT mapped-changerequest INTO DATA(request).                 
  mapped-user = VALUE #( BASE mapped-user                        
                         ( %tky = CORRESPONDING #( request-%tky )
                           %cid = request-%cid ) ).              
ENDLOOP.                                                         

 

 

But as mentioned before, no scenario get the child list updated after the action.

The function "side effects" has the option, that a entity will be reloaded after an action, but the feature is not available on our on-premise 2022 S/4HANA system:

actionWhenever the action is executed on the UI, the side effect is triggered and the defined targets are reloaded.

side effects { action MyAction affects Targets }

https://help.sap.com/docs/abap-cloud/abap-rap/side-effects#types-of-side-effects

Has anyone a suggestion how to achive this behavior?

View Entire Topic
ps_paolo
Discoverer
0 Kudos

Hi,

In case side effects in ABAP RAP are not available due to system version, you can solve this on the UI-side. When creating your (e.g.) Fiori Elements project in Business Application Studio you can use the annotation.xml file to overwrite or add additional annotations on top of you OData-Service. Fiori Elements understands the side effects, only in ABAP CDS it's yet (in 2022 release) not possible to add it.

You can find the documentation here: Side Effects. There are several examples, e.g. you can refresh properties or navigations (which might be relevant for you in case the children are reflected via a navigation). Look at the following examples.

hannemac
Participant

Thank you Paolo,

the approach with annotations worked for me:

 

<edmx:DataServices>
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="local">
        <Annotations Target="SAP__self.createChangeRequest(SAP__self.UserType)">
            <Annotation Term="Common.SideEffects">
                <Record Type="Common.SideEffectsType">
                    <PropertyValue Property="TargetEntities">
                        <Collection>
                            <NavigationPropertyPath>_it/_ChangeRequest</NavigationPropertyPath>
                        </Collection>
                    </PropertyValue>
                    <PropertyValue Property="TargetProperties">
                        <Collection>
                            <String>_it/_ChangeRequest/__EntityControl</String>
                        </Collection>
                    </PropertyValue>
                </Record>
            </Annotation>
        </Annotations>
    </Schema>
</edmx:DataServices>

 

I used "Guided Developments" to create the XML-code. Before I had to refresh the metadata.xml via right-click on manifest.js Open Service-Manager / Edit / Refresh & Save, to see all my created custom actions.

Thank you very much.

Best,
Christian