cancel
Showing results for 
Search instead for 
Did you mean: 

SAP MDK - How to edit an object inside another?

emorales
Explorer
0 Kudos
307

Hello community! As always, thanks for your help. I have the following problem...

I have a page called "Noticias_Detail.page", this page has two buttons: "Me gusta" and "No me gusta". The first button creates a record in the "NOTICIAPERSONALIKE" Entity database with its "LIKE" property set to "true". Right now everything works fine... so when I come back to this page and press the "No me gusta" button, my idea is to update the property of the previous record, making the "LIKE" property value false. This is my setup:

emorales_0-1726759621869.png

And this is my odata action to update entity:

emorales_3-1726759722578.png

When i try to press the "No me gusta" button I get the following error:

emorales_2-1726759695085.jpeg

I can't figure out what's going on. If I try to access this record in my CAP service, I can see it:

emorales_4-1726760069676.png

These are the entities in my CAP service (if that helps):

entity NOTICIA : cuid, AUDITORIA {
    TITULO : String100;
    CUERPO : String5000;
    EMPRESA: Association to one EMPRESA;
    AREA : Association to one AREA;
    AUTOR : Association to one PERSONA;
    NOTICIAPERSONALIKES: Composition of many NOTICIAPERSONALIKE on NOTICIAPERSONALIKES.NOTICIA = $self;
}

entity NOTICIAPERSONALIKE : cuid, AUDITORIA {
    NOTICIA : Association to one NOTICIA;
    USUARIOLIKE : Association to one PERSONA;
    LIKE : Boolean default true;
}

I accept any help or suggestion, thanks

View Entire Topic
bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Let me try to clarify for you.  In your first screen shot, the list page is targeting NOTICIA to display a list of all records in the entity set.  I am assuming you have an OnPress action on the Object Table to Navigate to the next screen shot.

Side note: When setting a target you use either Entity Set or Read Link but not both.

emorales_0-1726779642259.png

When the OnPress executes, the selected NOTICIA record from the list becomes the default binding object for the next page.  This means that when you bind values on the detail page you do not need to do another call to the odata service to get the data.  You can directly bind controls to the properties of the NOTICIA record.

In your second screen shot you have set the DesignTimeTarget for the page to the NOTICIAPERSONALIKE entity set.  The Design Time target is ONLY used by the Editor to help filter the Object Browser based to the Design time target to simplify picking properties.  

emorales_1-1726780155586.png

Without it the editor does not have any knowledge of what the default binding object will be when the page opens.  This property was added to make it easier for developers to define when they expect the default binding object to be when the page opens.  In your case I believe there may be a mismatch between what the default binding object is and what you have set as the Design Time Target but I could be wrong since I don't know from where and how the navigation was called.

From your CAP service there is a one to many relationship between NOTICIA and NOTICIAPERSONALIKE.  When a user first likes the NOTICIA there is no entry in NOTICIAPERSONALIKE and you can call CreateEntity targeting the NOTICIAPERSONALIKE entity set to create the entry.  However, once that entry exists you will need to call UpdateEntity and target the specific NOTICIAPERSONALIKE record to change the Like value.

In your third screenshot, the target is pointing to {@odata.readLink}/NOTICIAPERSONALIKES where I assume {@odata.readLink} points to the selected NOTICIA record.  In this case NOTICAPERSONALIKES is a navigation property to the list of all the likes for the NOTICIA and does not uniquely point to the one like for the current user.

emorales_2-1726779910074.png

To target the like for the current user you would either need the readLink for the existing user like or need to user query options and target the entity set.

EntitySet: NOTICIAPERSONALIKE
Query Options: $filter=NOTICIA eq '{NOTICIA}' and PERSONA = 'current user persona value'

These values are a guess.  If you can share the $metadata for NOTICIA and NOTICIAPERSONALIKE we can better identify what properties would be needed in the query options.

The error in your last screen shot is trying to tell you that the target for your UpdateEntity action is incorrect and does not uniquely point to a single record to be updated.

Hope this helps