/scripts/ahub.form.attachments.js
0

SAP UI5 oDataModel setProperty not working

Jun 02, 2017 at 01:26 PM

216

avatar image

Hi,

I am not able to set the value of a field in the oData model using setProperty, I am getting "false" as return value.

I have used a "CRUD Master-Detail Application" . From the Detail view, I navigate to Edit view. I have Input fields and a radio button on the Edit page. If I change the value of the Input field, the model is getting updated. For the radio button, I have a function for "select" property defined for RadioButtonGroup. I am getting the value(based on the selectedIndex) but when I am using setProperty on the oData Model, I am getting a false as a return.

In the controller for the Edit view, in "OnInit" function, I have a call for "_onEdit" function. I am using to bind the data to the view.

oPath = "/ItemsEntitySet(Index)" (Index selected on the Detail View)

oView.bindElement({

path: oPath

});

On Radio button selection, I am getting the selectedIndex and the value corresponding to the index and trying to set the value back to the oData Model(200 is the value to be set for the field in oData Model Items Entity. And oResult is "false".

var oResult = this.getModel().setProperty("/ItemsEntityDetail/Index/Field", "200");

Please let me know what I am missing. Other Input fields on the Edit view are automatically getting updated when their values are changed.

Thanks,

Anna

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Jun Wu Jun 02, 2017 at 01:48 PM
0

how about this?

path="/ItemsEntityDetail("+Index+")";

this.getModel().setProperty(path+"/Field", "200");

Share
10 |10000 characters needed characters left characters exceeded
Anna S Jun 02, 2017 at 02:03 PM
0

Hi Jun,

Thank you for the quick reply. I tried with your suggestion and it still didn't work.

Show 10 Share
10 |10000 characters needed characters left characters exceeded

show me your code, are u using jsonmodel or odatamodel?

0

It is oData Model.

var oPath1 ="/BankDetailSet("+index+")";

var oSet = this.getModel().setProperty(oPath1+"/Bkont", "02");

Do you want me to upload the project file?

0

var oPath1 ="/BankDetailSet('"+index+"')";

small change, surround the index with '

0

No change :(

I tried even with the Navigation name "BankDataNav" that I used in Detail view.

0

check in dev tool

give me a screenshot of your model object(with odata attribute expanded)

0

ss2.jpg

It looks like the issue is in the "if block". If I use the setProperty outside the if block, I am able to set the model.

Inside the "if block", my model is "undefined". I tried to fetch the model again inside the if block to rule out scope issues, but no luck. Please see varaibles oSet and oSet2 doing the same.. one outside and another inside the "if block". oSet is true and oSet2 is undefined. Can you please help me find what I am missing with the model?

ss2.jpg (252.7 kB)
0

I changed the comparison to "if (index == '1')"and now it works. I still do not know why "if (index === '1')" is an issue.

0
Show more comments

Master View

<List id="list" items="{ path: '/BankTypeSet', sorter: { path: 'Stext', descending: false }, groupHeaderFactory: '.createGroupHeader' }" busyIndicatorDelay="{masterView>/delay}" noDataText="{masterView>/noDataText}" mode="{= ${device>/system/phone} ? 'None' : 'SingleSelectMaster'}" growing="true" growingScrollToLoad="true" updateFinished="onUpdateFinished" selectionChange="onSelectionChange">

<infoToolbar>

<Toolbar active="true" id="filterBar" visible="{masterView>/isFilterBarVisible}" press="onOpenViewSettings">

<Title id="filterBarLabel" text="{masterView>/filterBarLabel}"/>

</Toolbar> </infoToolbar>

<items>

<ObjectListItem type="{= ${device>/system/phone} ? 'Active' : 'Inactive'}" press="onSelectionChange" title="{Stext}"></ObjectListItem>

</items>

</List>

Detail View

<List id="employeeList" items="{BankDataNav}">

<items>

<ObjectListItem title="Bank Name: {Banka}" iconDensityAware="false" number="{Bankn}">

<attributes>

<ObjectAttribute title="{ path: 'Begda', type: 'sap.ui.model.type.Date', formatOptions: { style: 'medium', UTC: true } }" text="{ path: 'Endda', type: 'sap.ui.model.type.Date', formatOptions: { style: 'medium', UTC: true } }"/>

<ObjectAttribute text="Bank Key: {Bankl} "/>

<ObjectAttribute title="Bank Control Key" text="{path: 'Bkont', formatter: '.conv2Text' }"/>

<ObjectAttribute title="Payment Method" text="{path: 'Zlsch', formatter: '.conv2Text' }"/>

</attributes>

</ObjectListItem>

</items>

</List>

Edit View

<f:SimpleForm id="SF_Id" maxContainerCols="2" layout="ResponsiveGridLayout" title="Edit : {Banka}" minWidth="1024" columnsL="1" columnsM="1" editable="true" emptySpanL="4" emptySpanM="4" labelSpanL="3" labelSpanM="3">

<f:content>

<Label text="Valid from" required="true"/>

<DatePicker name="Begda" value="{ path: 'Begda', type: 'sap.ui.model.type.Date', formatOptions: { style: 'medium', UTC: true, maxLength:15}}" id="Begda_id" enabled="{= ${viewModel>/mode} === 'edit'? true: false}" visible="true"/>

<Label text="Bank key number" required="true"/>

<Input name="Bankl" id="Bankl_id" valueLiveUpdate="true" liveChange="_validateSaveEnablement" enabled="{= ${viewModel>/mode} === 'edit'? true: false}" visible="true" value="{Bankl}"/>

<Label text="Bank account" required="true"/>

<Input name="Bankn" id="Bankn_id" valueLiveUpdate="true" liveChange="_validateSaveEnablement" enabled="{= ${viewModel>/mode} === 'edit'? true: false}" visible="true" value="{Bankn}"/>

<Label text="Account type" required="true"/>

<RadioButtonGroup select="onSelectRadio" columns="2" id="RBG_Id">

<buttons>

<RadioButton id="RB1-1" text="Checking account"/>

<RadioButton id="RB1-2" text="Savings account"/>

</buttons>

</RadioButtonGroup>

</f:content>

</f:SimpleForm>

0
Skip to Content