Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3347

SAPUI5 write NavigationProperty in oData 2.0 (BestPractice)

$
0
0
Hi,

I am developing a simple sapui5 1.38.x based of a Master Detail template.

My Master is an Entity called Project and the entity set is called Projects.

In the Project there is a NavigationProperty called Currency it is a simple relation many2one on the database

 

you can see the snipper of the $metadata of this two entity

 

<EntityType Name="Project">

<Key>

  <PropertyRef Name="Id"/>

</Key>

<Property Name="Description" Type="Edm.String" Nullable="false" MaxLength="255"/>

<Property Name="Id" Type="Edm.Int64" Nullable="false"/>

<Property Name="Price" Type="Edm.Single"/>

<NavigationProperty Name="Currency" Relationship="org.uurla.projects.projman.db.persistence.Project_Currency_Many_One0" FromRole="Project" ToRole="Currency"/> 

<NavigationProperty Name="Tasks" Relationship="org.uurla.projects.projman.db.persistence.Project_Task_One_Many0" FromRole="Project" ToRole="Task"/>

</EntityType>

as you can see the NavigationProperty "Currency" refer to the Entity

<EntityType Name="Currency">

  <Key>

    <PropertyRef Name="Curcod"/>

  </Key>

  <Property Name="Curcod" Type="Edm.String" Nullable="false" MaxLength="4"/>

  <Property Name="Curdes" Type="Edm.String" Nullable="true" MaxLength="20"/>

</EntityType>

My question is: what is the best practice to create a Project with SAPUI5?
I try to use different solutions especially what is specified in the
open sap course "Developing Web Apps with SAPUI5" week 4 unit 2 but the Currency field of the table Project on the database is create empty
I debug the javascript code and I noted that whatever property in the object is equal to a NavigationProperty, it is automatically remove from the creation request.
The standard oDataV2 service want the following POST as you can see the property "Currency" must be there

URL
<serviceurl>/Projects

HEADER
Content-Type: application/json

BODY

{

  "Description":"prova312",

  "Price":1,

  "Currency":  { "__metadata":

    {

          "uri": "Currencys('EUR')",

          "type": "org.uurla.projects.projman.db.persistence.Currency"

                        }

        },

  "__metadata":{

      "type":"org.uurla.projects.projman.db.persistence.Project",

      "uri":"Projects('id-1471129553866-22')"

               }

}



so I use the way explained in the classic two following youtube howto and it works but I do not like use directly the method OData.request() how it is explained in the following howto

SAPUI5 - oData Operations (Create/Update/Delete) - Part 1 - YouTube

SAPUI5 - oData Operations (Create/Update/Delete) - Part 2 - YouTube

can someone suggest a different way to solve the problem?
thank you in advanced
Domenico

 


Viewing all articles
Browse latest Browse all 3347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>