cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple questions with oData v4

smarchesini
Active Contributor
0 Kudos

Hello everyone,

I'm new to oData v4 and I'm starting to use it in a SAPUI5 project after implementing CAP with a Postgres DB.

Currently, the scenario is as follows: Entity Template has multiple TemplateFields.

I have several questions regarding this:

 

 

...
<EntityType Name="Template">
                <Key>
                    <PropertyRef Name="Template_ID"/>
                </Key>
                <Property Name="createdAt" Type="Edm.DateTimeOffset" Precision="7"/>
                <Property Name="createdBy" Type="Edm.String" MaxLength="255"/>
                <Property Name="modifiedAt" Type="Edm.DateTimeOffset" Precision="7"/>
                <Property Name="modifiedBy" Type="Edm.String" MaxLength="255"/>
                <Property Name="Template_ID" Type="Edm.String" Nullable="false"/>
                <Property Name="Description" Type="Edm.String"/>
                <NavigationProperty Name="Fields" Type="Collection(LaborTrackingService.TemplateFields)"/>
            </EntityType>
			<EntityType Name="TemplateFields">
                <Key>
                    <PropertyRef Name="Element"/>
                    <PropertyRef Name="Status"/>
                    <PropertyRef Name="Template_ID"/>
                </Key>
                <Property Name="Element" Type="Edm.String" Nullable="false"/>
                <Property Name="Status" Type="Edm.String" Nullable="false"/>
                <Property Name="Template_ID" Type="Edm.String" Nullable="false"/>
                <NavigationProperty Name="Template" Type="LaborTrackingService.Template">
                    <ReferentialConstraint Property="Template_ID" ReferencedProperty="Template_ID"/>
                </NavigationProperty>
                <Property Name="Visible" Type="Edm.Boolean"/>
                <Property Name="Editable" Type="Edm.Boolean"/>
                <Property Name="Mandatory" Type="Edm.Boolean"/>
            </EntityType>
...

 

 

 

  • 1- How can I dynamically bind it to my view? The following code is functional, but I want to avoid hardcoding the keys. I aim to make it dynamic based on our requirements (Template and Status should be dynamic).

 

 

<m:Button id="idBtnSave2" text="{i18n>btnSave}" visible="{path: '/TemplateFields(Template_ID=\'TEMPGEN\',Element=\'Comment\',Status=\'INITIAL\')/Visible', type: 'sap.ui.model.odata.type.Boolean'}" />

 

 

  • 2- I attempted to select all the TemplateFields and then manipulate the result with either the event data receiver or the formatter. However, it did not work as expected.

 

 

<m:TextArea id="idComment" visible="{path : '/TemplateFields', events : { dataRequested : '.onDataReceived' }, formatter:'.setVisibility' }"  />​

 

Error:
2024-03-05 14:47:34.099000 FormatException in property 'visible' of 'Element sap.m.TextArea#application-labor_traking-edit-component---MainView--idComment': Type 'sap.ui.model.odata.type.Raw' does not support formatting

 

  • 3 - If I attempt to retrieve data directly from the CDS using the parameters provided in the documentation, I encounter errors:

    Uncaught (in promise) Error: System query option $select is not supported
    Uncaught (in promise) Error: System query option $top is not supported
    Uncaught (in promise) Error: System query option $filter is not supported

    In my example, I aim to select the Visibility of the first element by filtering for predefined data (in any case, we face the issue mentioned in point 1).

 

 

<m:Input id="idTest1" visible="{path : '/TemplateFields', parameters : { $select: 'Visible', $top : 1, $filter : 'Template_ID eq \'TEMPGEN\''}, events : { dataRequested : '.onDataReceived' } }"  />

 



 

  • 4 - If I resort to using the controller and JavaScript, I must bind field by field correctly. Do you believe there is a possible solution to this, with the controller?

     

To conclude those are the data:

smarchesini_0-1709668838521.png



Thank you,
Sebastiano

Accepted Solutions (0)

Answers (1)

Answers (1)

smarchesini
Active Contributor
0 Kudos

I decide to use simple ajax call and anti-pattern JSON Model because I have no time to study and implement another solution.
 
Here a blog could be useful:
https://community.sap.com/t5/technology-blogs-by-sap/implementing-crud-operations-in-odata-v4/ba-p/1...