Skip to Content

Unable to pass values from object to local json file


I have created a table and displayed data in it from a local json file. On adding a new entry I need to update the json file as well as the table. I am unable to update the table on adding.

I have provided the code below.

Controller code:

], function(Controller) {
	"use strict";

	return Controller.extend("craete_operations.controller.View", {
		onInit: function() {
			var oModel = new sap.ui.model.json.JSONModel("model/Details.json");
		onAdd: function(oEvent) {
			if (!this._oDialog) {
				this._oDialog = sap.ui.xmlfragment("craete_operations.view.View", this);

			// toggle compact style"sapUiSizeCompact", this.getView(), this._oDialog);;
		onAddDetails: function() {
			var ID = sap.ui.getCore().byId("ID").getValue();
			var Name = sap.ui.getCore().byId("Name").getValue();
			var Mob = sap.ui.getCore().byId("Mobile").getValue();
			var Dep = sap.ui.getCore().byId("Department").getValue();

			var object = {
				EmpID: ID,
				EmpName: Name,
				Mobile: Mob,
				Dept: Dep

			var oModel = new sap.ui.model.json.JSONModel("model/Details.json");
				EmpDetails: object
		onClose: function(oEvent) {

View code:

<mvc:View controllerName="craete_operations.controller.View" xmlns:html="" xmlns:mvc="sap.ui.core.mvc"
	displayBlock="true" xmlns="sap.m">
			<Page title="{i18n>title}">
					<Table id="Table" items="{path:'/EmpDetails'}">
								<Title text="Employee Details" level="H2"/>
							<Column width="12em">
								<Text text="Emp ID"/>
							<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Left">
								<Text text="Emp Name"/>
							<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Left">
								<Text text="Mobile No"/>
							<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Left">
								<Text text="Department"/>
									<Text text="{EmpID}"/>
									<Text text="{EmpName}"/>
									<Text text="{Mobile}"/>
									<Text text="{Dept}"/>
					<Button text="Add" press="onAdd" class="sapUiSmallMarginBottom"/>

Fragment for dialog:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" controllerName="craete_operations.controller.View">
	<Dialog title="Add Details" class="sapUiContentPadding">
					<InputListItem label="Employee Id" id="item0">
							<Input ariaLabelledBy="item0-label" width="100%" id="ID"/>
					<InputListItem label="Employee Name" id="item1">
							<Input ariaLabelledBy="item1-label" width="100%" id="Name"/>
					<InputListItem label="MobileNo" id="item2">
							<Input ariaLabelledBy="item2-label" width="100%" id="Mobile"/>
					<InputListItem label="Department" id="item3">
							<Input ariaLabelledBy="item3-label" width="100%" id="Department"/>
					<Button text="Add" press="onAddDetails"/>
			<Button text="Cancel" press="onClose"/>

Details.json(local file)

	"EmpDetails": [{
		"EmpID": "4",
		"EmpName": "John",
		"Mobile": "937642343",
		"Dept": "Java"
	}, {
		"EmpID": "5",
		"EmpName": "Xavier",
		"Mobile": "7213213234",
		"Dept": "SAP"

Please help me to update the table.

Thanks in advance,


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Oct 27, 2017 at 10:16 AM

    Hi Janani,

    as per your post I understood that when you are performing CURD Operations you need Add/Delete/Update Records in your Table as well as JSON File.

    Here coming to Update JSON File from CURD Operations Might not be Possible as Junwu.

    Now for coming to Update Data in Table after Performing CURD Operation can be done,but the life time of the added record is just in that session only.

    Here this can be done by below procedure.

    For Add

    First get the already binded Model and respective data and store it in an array.Then after add the Object to that array and bind it to the table.Similarly for Update and Delete.



    Add comment
    10|10000 characters needed characters exceeded

  • Oct 26, 2017 at 06:50 AM


    you want to add new row into the table not in json file right?

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 26, 2017 at 09:08 AM

    oModel.setData({EmpDetails:object}, true);

    This should update the local json file with new object in the add method.

    if you have bound the table to json correctly, then it should display the update row in the table. Else, trigger a refresh on the table.



    Add comment
    10|10000 characters needed characters exceeded

  • Oct 26, 2017 at 06:32 PM

    not possible to add record to the file.

    Add comment
    10|10000 characters needed characters exceeded