cancel
Showing results for 
Search instead for 
Did you mean: 

SAP MDK - How to edit an object inside another?

emorales
Explorer
0 Kudos
98

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

To update the likes records when returning you need to target the specific like record.  The error message indicates you are trying to target the navigation property from the NOTICIA record instead of the NOTICIAPERSONALIKE record.  

emorales
Explorer
0 Kudos

Hi bill, Hi Bill! Thanks, I understand what you mean, I did what you say (I think) and I get this error:

emorales_0-1726765528697.png

emorales_1-1726765537258.jpeg

 

 

panushjain
Product and Topic Expert
Product and Topic Expert
0 Kudos

In the OdataNoticia_PersonalLikeEdit.action, what if you remove /NOTICIAPERSONALIKES from the Entity Set and instead pass it in the QueryOptions. Does it behave the same?

image.png

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos
You need to make sure your {@odata.readLink} is pointing to the specific NOTICIAPERSONALIKE record you want to update. Depending on your page and how you navigated to this page I am guessing it is pointing to NOTICIA instead. You would need to lookup or have access to the correct readLink or use the appropriate Query Options to point to the one record to be updated.
emorales
Explorer
0 Kudos

Thanks for the help, I still have the same problem. I don't understand what I'm doing wrong, I'm sharing screenshots of the entire process:

In this view I see all the available news

emorales_0-1726779642259.png

When I select a particular one, I enter the detail view:

emorales_1-1726780155586.png

The "No me gusta" button triggers the following action:

emorales_2-1726779910074.png

And I get the following error:

emorales_3-1726780027314.jpeg

I've tried many variants and none of them work.