0

I'm currently using OData v4 requests from my CAP app, and the problem is how to bind my Entity requested data in my Simple Form.

The user must input a Workspace code, and Search for its values. Please, how do I bind and display my Workspace name and description values to my Simple Form fields to be displayed on screen?

Workspace CAP entity data:

{
"@odata.context": "$metadata#Workspace/$entity",
"name": "Projeto Compra de Material Escritorio",
"description": "",
"projectState": "Active",
"testProject": "false",
"version": "Original",
"baseLanguage": "pt"
}

in the onInit app function

                let oModel = new sap.ui.model.odata.v4ODataModel({
                    groupId : "$auto",
                    synchronizationMode : "None",
                    serviceUrl : "/myCAP_URL/"

in my press event button

                let oModel = this.getView().getModel();
                let oContextBinding = oModel.bindContext(`/Workspace/${workspaceId}`);
                
                oContextBinding.requestObject("name").then(function (sName) {
                    if (!sName) {
                        oContextBinding.getBoundContext().setProperty("name", "No name");
                    }
                });

Finally, that`s my Simple Form fields (XML)

            <Button id="button0" press="onPress" text="Search"/>
            
            <f:SimpleForm editable="true" layout="ResponsiveGridLayout" id="form0">
                <f:content>
                    <sap.ui.core:Title text="{description}" id="title2"/>
                    
                    <Label text="Name" id="label0"/>
                    <Input width="30%" id="input0" value="{name}"/>

                    <Label text="Language" id="label1"/>
                    <Input width="30%" id="input2" value="{baseLanguage}"/>

                </f:content>
            </f:SimpleForm>

1 Answers1

0

I've managed to bind and display data, based on this piece of code. I`ve just made some adjustments.

oContextBinding.requestObject("name").then(function(sName) {
  if (!sName) {
    oContextBinding.getBoundContext().setProperty("name", "No name");
  }
});
Tyler2P
  • 2,324
  • 26
  • 22
  • 31