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?

Accepted Solutions (1)

Accepted Solutions (1)

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

 

Answers (1)

Answers (1)

Edrilan_Berisha
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

 

the list should be refreshed when you hand over the right object after it was created. You should look deeper into your ABAP coding.

 

Another way to achieve refresh (which I would recommend only if you come from the frontend - so you have triggered some special logic on the frontend side and you want to refresh it):

https://sapui5.hana.ondemand.com/sdk/#/api/sap.suite.ui.generic.template.ObjectPage.extensionAPI.Ext...

 

You could implement such a breakout coding by using the refresh method on the extensionAPI.

 

Best,

Edrilan Berisha

SAP S/4HANA Cloud Financials Development

hannemac
Participant
0 Kudos

Hi Edrilan Berisha,

thank you for your comment.

The question is, what is the "right object".
As described, I tried the Root-Object and the Child-Object. Non of them worked.

Could you be maybe a little bit more specific about the object?

Many thanks and best regards,
Christian