0

I have redefined my App which is a Master-Detail app. The point is that I use a Main Entity Type with a relation to 3 entities. My question is:

In the Detail view I use a DynamicPage with some info from Main entity (Name of Customer and so on...) an below, I show 3 tabs and in each tab, I am presenting the info by calling the navigation/association in the main entity/model, for example Header2Order/fieldx.

In this particular Fragment:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:smartForm="sap.ui.comp.smartform" xmlns:smartField="sap.ui.comp.smartfield" xmlns:form="sap.ui.layout.form" xmlns:l="sap.ui.layout"   xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1">
    <VBox class="sapUiSmallMargin" id="VBox">
        <smartForm:SmartForm id="smartForm" editTogglable="false" title="{i18n>TITLE}"
            editable="{screenSetup>/bEditable}">
            <smartForm:Group>
                <smartForm:GroupElement label="{i18n>Order}" id="groupElementOrder">
                    <smartField:SmartField value="{Header2Order/OrderTxt}" tooltipLabel="{i18n>ORDERTXT}" id="smartFieldOrderTxt">
                        <smartField:configuration>
                            <smartField:Configuration preventInitialDataFetchInValueHelpDialog="false"/>
                        </smartField:configuration>
                    </smartField:SmartField>
                </smartForm:GroupElement>
                <smartForm:GroupElement label="{i18n>VALID_FROM}" useHorizontalLayout="true" id="groupElementValidFrom">
                    <smartField:SmartField id="smartFieldValidFrom" value="{Header2Order/ValidFrom}" tooltipLabel="{i18n>VALID_FROM}"/>
                </smartForm:GroupElement>
                <smartForm:GroupElement label="{i18n>VALID_TO}" useHorizontalLayout="true" id="groupElementValidTo">
                <smartField:SmartField id="smartFieldValidTo" value="{Header2Order/ValidTo}" tooltipLabel="{i18n>VALID_TO}"/>
                </smartForm:GroupElement>
                <smartForm:GroupElement id="groupElementText" label="{i18n>COMMENT}">
                    <smartField:SmartField id="smartFieldText" value="{Header2Order/Comment}" app:multiLineSettings="{cols: 100, rows: 4}"/>
                </smartForm:GroupElement>
            </smartForm:Group>
        </smartForm:SmartForm>
    </VBox>
</core:FragmentDefinition>

I would like to create a new entry on the same view, for that, in my Detail.controller.js, I am using:

_createNewComment: function () {
   if (view.byId("iconTabBar").getBindingContext() !== null) {
      this._sBindingPath = null;
      this._sBindingPath = view.byId("iconTabBar").getBindingContext().getPath();
      var sBinding = this._sBindingPath + "/Header2Order"
      this._oContext = view.getModel().createEntry(sBinding, {
                                                   properties: this._setODataDefaulted()
      });

      sBinding = this._oContext.getPath() + "/Header2Order"; " Binding the Relative Path??
      view.byId("iconTabBar").bindElement({
                        path: this._oContext.getPath(),
                        model: sBinding
            });
   }
},

I am generating a proper Model based on the Entity extracted from the Navigation but I cannot link it to the Fragment properly cause I use {Header2Order/ValidTo} instead {ValidTo} and when I bind the new Context to the Element, it doesn't work.

I would like to know if you know a direct way to do it in this way or if it will be easier to extract the data from the call to the Association, generate a new Model in the context and bind it to the view/fragment.

Thanks!!

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
RaulCB
  • 79
  • 9
  • 1
    Did you see https://stackoverflow.com/a/31293881/1960986. Result of createEntry can be at direct to any control. – Benedikt Kromer Jul 04 '21 at 22:06
  • Hi Benedikt Kromer, no, obviously I didn't read it. I searched by ```createEntry()```. Thanks for pointing me at the right direction! – RaulCB Jul 05 '21 at 05:24
  • @BenediktKromer, I tried in many ways (all I could think about) following the example in the link you posted. The issue is that I am generating a context from the ```createEntry()``` method and it takes the proper entitySet and so on. During the call of ```createEntry``` I cannot assign the model's name or I don't find the proper place to assign it. Once the new Context is generated, I can assign it but as I mentioned, it doesn't work. all inputs are more than welcome... – RaulCB Jul 06 '21 at 06:14
  • 1
    why would you like to "assign the model's name" ? ```createEntry``` is to create entries which will be submitted later via batch. Hence the entry lives in the model you can't simply move it to another one(best practise is to have per app just one oData model). Placing a newly create(still local) entry under a navigation path never worked with ui5 and should be avoided; at least thats my experience. There is a reason why draft enabled apps move data immediately to the backend. Maybe someone else can tell us if this works with a recent ui5 version. – Benedikt Kromer Jul 06 '21 at 08:13
  • @BenediktKromer, when you work with associations, how do you handle the creation of a new entry in one association (only in this association)? that's my point. Sorry for "stupid" questions but I am still learning and I don't connect all points in my brain, not yet... I have the entities -- Main and Order, I have an association Main2Order which I use in my View as ```{Main2Order/field}```. I want to create a new entry only for the association. ```createEntry``` the context is based on ```OrderSet```, how can I use fields from ```orderset``` in my view?? The view has SmartformFields. – RaulCB Jul 06 '21 at 09:56
  • 1
    It looks like you want to use batch and this is tricky. Ignoring batch; the simplest way to create something under an association is to create the Entity```order```(which has to have a property, holding the ID of ```main```) and then refresh Main along the navigation property ```Main2Order ```. I saw also apps creating data in a JSON-Model and constructing batch request when the user is pressing save. As is said what you want never worked in older ui5-versions. maybe someone else knows more. I avoid such thing a build always draft like e.g. push data to the backend as soon as possible – Benedikt Kromer Jul 06 '21 at 10:10
  • Thanks @BenediktKromer. To go for your suggestion, I should not use the Association within the view for displaying/introducing values, right? I should split that info in a new model and bind the "new" model with Order to the view. – RaulCB Jul 06 '21 at 11:04
  • 1
    Every app has/should have only one OData model. Your Datamodel should always use navigation properties - so displaying works out of the box. You can push create/update immediately to te backend and refresh afterwards OR transfer the data always in a json-model, display update/create within the json model and write a submitBatch where you build requests as needed. OR maybe someone else will answer here; as i said i didn't try this for a few years. Maybe ui5 was improved. – Benedikt Kromer Jul 06 '21 at 11:10
  • In the official [documentation](https://ui5.sap.com/sdk#/api/sap.ui.model.odata.v2.ODataModel%23methods/createEntry) says: **Please note that deep creates (including data defined by navigation properties) are not supported. The parameter expand is supported since 1.78.0. If this parameter is set, the given navigation properties are expanded automatically with the same $batch request in which the POST request for the creation is contained. ...** – RaulCB Jul 07 '21 at 06:53
  • Deep create is creating a deep entity, parent + child. Not related to your question. – Benedikt Kromer Jul 07 '21 at 14:32

0 Answers0