Skip to Content
0

I am trying to implement create operation of the crud but i am getting an error

Feb 10, 2017 at 09:24 AM

174

avatar image

view.pngi am getting the following error from the browser but no error in the controller

failed to load 'club/club/Create.controller.js' from ./club/Create.controller.js: SyntaxError: Unexpected identifier

sap.ui.controller("club.club.Create", {
	onInit: function() {
},
handleBackPress: function (oEvent) 
	{
		var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
		oRouter.navTo("schedule");
	},
handSubmitPress: function(oEvent)
	{
		
		 var oId = this.getView().byId("MatchId");
		 oId.setEditable(true);
		 oId.setValue("");
		
		 var oId = this.getView().byId("MatchDate");
		 oId.setEditable(true);
		 oId.setValue("");
		 
		 var oId = this.getView().byId("HomeTeam");
		 oId.setEditable(true);
		 oId.setValue("");
		 
		 var oId = this.getView().byId("AwayTeam");
		 oId.setEditable(true);
		 oId.setValue("");
		 
		 var oId = this.getView().byId("MatchType");
		 oId.setEditable(true);
		 oId.setValue("");
		 
		 var oId = this.getView().byId("Week");
		 oId.setEditable(true);
		 oId.setValue("");
		 
		 var oId = this.getView().byId("Location");
		 oId.setEditable(true);
		 oId.setValue("");
		  
			view = this.getView();
			var oForm = this.getView().byId("createForm");
				{
					var oId = this.getView().byId("MatchId").getValue();
					var MatchDate = this.getView().byId("MatchDate").getValue();
					var HomeTeam = this.getView().byId("HomeTeam").getValue();
					var AwayTeam = this.getView().byId("AwayTeam").getValue();
					var MatchType = this.getView().byId("MatchType").getValue();
					var Week = this.getView().byId("Week").getValue();
					var Location = this.getView().byId("Location").getValue();
					
					OData.request
							({
								requestUri: "http://eccehp7.erp.com:8000/sap/opu/odata/sap/ZYK_SCHEDULE_SRV_01",
								method: "GET",
								user: "SAP_TRAINEE",
								password: "",
								headers: {
											"X-Requested-With" : "XMLHttpRequest",
											"Content-Type" : "application/json",
											"DataServiceVersion" : "2.0",
											"X-CSRF-Token" : "Fetch",
											"Access-Control-Allow-Origin": "*",  
											 "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,OPTIONS",  
										     "Access-Control-Allow-Headers": "Origin, Content-Type, Authorization, Accept, X-Request-With",  
											 "Access-Control-Allow-Credentials": "true",
											 'Authorization' : 'Basic ' + btoa("username" + ':password')
										 }				
								},
		function (data, response)
		{
			header _xcsrf_token = response.headers['x-csrf-token'],
			OData.request
			({
				requestUri: "http://eccehp7.erp.com:8000/sap/opu/odata/sap/ZYK_SCHEDULE_SRV_01/SheduleSet",
				method: "POST",
				headers: {
							"X-Requested-With" : "XMLHttpRequest",
							"Content-Type" : "application/atom-xml",
							"DataServiceVersion" : "2.0",
							"Accept" : "application/atom-xml,", 
							"X-CSRF-Token" : header_xcsrf_token,
							"Access-Control-Allow-Origin": "*",
				             "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,OPTIONS",
				             "Access-Control-Allow-Headers": "Origin, Content-Type, Authorization, Accept, X-Request-With",
				             "Access-Control-Allow-Credentials": "true",
				             'Authorization' : 'Basic ' + btoa("username" + ':password')
						  },
				data:
					{
						MatchId : MatchId,
						MatchDate : MatchDate,
						HomeTeam : HomeTeam,
						AwayTeam : AwayTeam,
						MatchType : MatchType,
						Week : Week,
						Location : Location, 
					}
			},
			function (data, response)
			{
				var oSubDialog = new sap.ui.commons.Dialog
				({
					title: "Created",
					content: [
					          new sap.ui.commons.Label
					          ({
					        	  text: "Data Created Successfully"
					          })
					         ]
				});
				
				
				oSubDialog.open();
				oSubDialog.addButton
				(
						new sap.ui.commons.Button
						({
					text: "Ok",
					press: function()
					{
						oSubDialog.close();
					}
						})
				);
				
				sap.ui.getCore().getModel().refresh();
			},
			function(err)
			{
				alert("Create Error");
			}
			);
		},
		function(err)
		{
			var request = err.request;
			var response = err.response;
			alert("Error in Post Method" +request+ "Response" +response);
		})
}
}
});
view.png (119.2 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Akhilesh Upadhyay Feb 10, 2017 at 12:40 PM
1

I guess below line is causing issue:

header _xcsrf_token = response.headers['x-csrf-token'],

change the place of this line or use response directly instead of creating new variable.

or check and verify the namespace of your controller file once i.e. sap.ui.controller("club.club.Create", {........

-Akhilesh

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

namespace is correct its not the issue i checked it many times

0

:)

since this is bad naming convention you have used so highlighted. Anyway.

I think its syntax error only in the above line and instead of , (comma) put ; (semicolon) end of the above mentioned line, because that line is altogether different dont associate with the rest of the code inside function. In your current code it will be treated like an argument which been messed up.

-Akhilesh

0

checked it but still the same issue

thanks Yadnesh

0

i checked your code:

you have kept extra(unnecessary) { in below line:

var oForm = this.getView().byId("createForm");{ // { is no required

and also closing bracket (}), remove from end of function.

And

you have missed ; at the end of last function

function(err){
	var request= err.request;
	var response = err.response;
	alert("Error in Post Method" +request+ "Response" +response);

}); //; is missing in your code

few correction i have made, pls check that.

sap.ui.controller("club.club.Create", {
onInit: function() {},
handleBackPress: function(oEvent) {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("schedule");
},
handSubmitPress: function(oEvent) {
var oId = this.getView().byId("MatchId");
oId.setEditable(true);
oId.setValue("");
var oId = this.getView().byId("MatchDate");
oId.setEditable(true);
oId.setValue("");
var oId = this.getView().byId("HomeTeam");
oId.setEditable(true);
oId.setValue("");
var oId = this.getView().byId("AwayTeam");
oId.setEditable(true);
oId.setValue("");
var oId = this.getView().byId("MatchType");
oId.setEditable(true);
oId.setValue("");
var oId = this.getView().byId("Week");
oId.setEditable(true);
oId.setValue("");
var oId = this.getView().byId("Location");
oId.setEditable(true);
oId.setValue(""); 
var oForm = this.getView().byId("createForm");
var MatchId = this.getView().byId("MatchId").getValue();
var MatchDate = this.getView().byId("MatchDate").getValue();
var HomeTeam = this.getView().byId("HomeTeam").getValue();
var AwayTeam = this.getView().byId("AwayTeam").getValue();
var MatchType = this.getView().byId("MatchType").getValue();
var Week = this.getView().byId("Week").getValue();
var Location = this.getView().byId("Location").getValue();
OData.request({
requestUri: "http://eccehp7.erp.com:8000/sap/opu/odata/sap/ZYK_SCHEDULE_SRV_01",
method: "GET",
user: "SAP_TRAINEE",
password: "",
headers: {
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/json",
"DataServiceVersion": "2.0",
"X-CSRF-Token": "Fetch",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,OPTIONS",
"Access-Control-Allow-Headers": "Origin, Content-Type, Authorization, Accept, X-Request-With",
"Access-Control-Allow-Credentials": "true",
'Authorization': 'Basic ' + btoa("username" + ':password')
}
},
function(data, response) {
OData.request({
requestUri: "http://eccehp7.erp.com:8000/sap/opu/odata/sap/ZYK_SCHEDULE_SRV_01/SheduleSet",
method: "POST",
headers: {
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom-xml",
"DataServiceVersion": "2.0",
"Accept": "application/atom-xml,",
"X-CSRF-Token": response.headers['x-csrf-token'],
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,OPTIONS",
"Access-Control-Allow-Headers": "Origin, Content-Type, Authorization, Accept, X-Request-With",
"Access-Control-Allow-Credentials": "true",
'Authorization': 'Basic ' + btoa("username" + ':password')
},
data: {
MatchId: MatchId,
MatchDate: MatchDate,
HomeTeam: HomeTeam,
AwayTeam: AwayTeam,
MatchType: MatchType,
Week: Week,
Location: Location,
}
},
function(data, response) {
var oSubDialog = new sap.ui.commons.Dialog({
title: "Created",
content: [
new sap.ui.commons.Label({
text: "Data Created Successfully"
})
]
});
oSubDialog.open();
oSubDialog.addButton(
new sap.ui.commons.Button({
text: "Ok",
press: function() {
oSubDialog.close();
}
})
);
sap.ui.getCore().getModel().refresh();
},
function(err) {
alert("Create Error");
}
);
},
function(err) {
var request = err.request;
var response = err.response;
alert("Error in Post Method" + request + "Response" + response);
});
}
});

Also, i dont know what you are trying to achieve here, but while submitting data you are setting blank (" ") value to controls, and then you are taking back that controls value in another variables and passing it to service. you are doing something funny here, if you wants to pass blank values only so why are setting values to controls and getting back in another variables, you could have pass blank values to service only.

Anyway, above code may help.

-Akhilesh

0
Srikanth KV Feb 10, 2017 at 05:01 PM
0

I think controller first line is wrong. It should extend from sap.ui.core.mvc.Controller.

https://sapui5.hana.ondemand.com/#docs/guide/50579ddf2c934ce789e056cfffe9efa9.html


controller.png (19.9 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded

its not the problem as i checked it using your code too but the same error arises again. I am guessing its a brackets error but i cant find where exactly it is coming from

0