Skip to Content
0
Oct 11, 2016 at 01:44 PM

Create ticket using Date Picker control in SAPUI5

541 Views Last edit Oct 11, 2016 at 01:44 PM 3 rev

Hi Experts,

My requirement is to create new ticket on getting required details from the user. So far, I have created a Dialog box with text fields to get the data from the user. When I use the Date Picker control and create tickets I get the error

"sap-ui-core.js:160 2016-10-11 15:35:56.020379 The following problem occurred: HTTP request failed400,Bad Request, 00145E5B1CC71EE0AB8B3A3B086F432E http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> 00145E5B1CC71EE0AB8B3A3B086F432E xml:lang="en">The Data Services Request could not be understood due to malformed syntax "

Is the error occurring because the date format in the control is the not understood by the odata while creating tickets ?

If so, please provide suggestions as to how this can be accomplished.

The code to create ticket:

createticket: function() {
			var oModel = new sap.ui.model.odata.ODataModel("/sap/c4c/odata/v1/c4codata/");
			// Create a dialog to get the information of the bank to be created
			var oDialog = new sap.ui.commons.Dialog("Dialog", {
				modal: true,
				closed: function(oControlEvent) {
					sap.ui.getCore().getElementById('Dialog').destroy();
				}
			});
			oDialog.setTitle("Create Ticket");
			// Create a layout to place the controls in the dialog
			var oLayout = new sap.ui.commons.layout.MatrixLayout({
				columns: 2,
				width: "100%"
			});
			var oTF = new sap.ui.commons.TextField("serialid", {
				tooltip: "Serial ID",
				editable: true,
				required: true,
				width: '200px'
			});
			var oLabel = new sap.ui.commons.Label("Serialid", {
				text: 'SerialID',
				labelFor: oTF
			});
			oLayout.createRow(oLabel, oTF);
			oTF = new sap.ui.commons.TextField("prodid", {
				tooltip: 'Product ID',
				editable: true,
				required: true,
				width: '200px'
			});
			// Label for the last name field
			oLabel = new sap.ui.commons.Label("ProductID", {
				text: 'ProductID',
				labelFor: oTF
			});
			oLayout.createRow(oLabel, oTF);
			oTF = new sap.ui.commons.TextField("custid", {
				tooltip: 'Customer ID',
				editable: true,
				required: true,
				width: '200px'
			});
			// Label for the last name field
			oLabel = new sap.ui.commons.Label("CustomerID", {
				text: 'CustomerID',
				labelFor: oTF
			});
			oLayout.createRow(oLabel, oTF);
				oTF = new sap.m.DatePicker("wtstid", {
				tooltip: 'Sart Date',
				editable: true,
				required: false,
				width: '200px'
			});
			// Label for the last name field
			oLabel = new sap.ui.commons.Label("WarrantyFrom", {
				text: 'Warranty From',
				labelFor: oTF
			});
			oLayout.createRow(oLabel, oTF);
			oTF = new sap.m.DatePicker("wteddate", {
				tooltip: 'End Date',
				editable: true,
				required: false,
				width: '200px'
			});
			// Label for the last name field
			oLabel = new sap.ui.commons.Label("WarrantyEnd", {
				text: 'Warranty To',
				labelFor: oTF
			});
			oLayout.createRow(oLabel, oTF);
			// Add the layout to the dialog
			oDialog.addContent(oLayout);
			// Add a button to post the bank's data to the odata interface
			oDialog.addButton(new sap.ui.commons.Button({
				text: "Save",
				press: function() {
					var serialid = sap.ui.getCore().byId("serialid").getValue();
					var prodid = sap.ui.getCore().byId("prodid").getValue();
					var custid = sap.ui.getCore().byId("custid").getValue();
					var wtstid = sap.ui.getCore().byId("wtstid").getValue();
					var wteddate = sap.ui.getCore().byId("wteddate").getValue();
					var oEntry = {};
					oEntry.SerialID = serialid;
					oEntry.ProductID = prodid;
					oEntry.CustomerID = custid;
					oEntry.WarrantyFrom = wtstid;
					oEntry.WarrantyTo = wteddate;			
					oModel.create("/ServiceRequestCollection", oEntry, null, function() {
					var msg = 'New Service Ticket has been created successfully.';
					MessageBox.show(msg);
				},function() {
					var msg = 'Service Ticket Creation has failed.';
					MessageBox.show(msg);
				});
					oDialog.close();
				}
			}));
			oDialog.addButton(new sap.ui.commons.Button({
				text: "Cancel",
				press: function() {
					var msg = 'Service Ticket Creation has been cancelled.';
					MessageBox.show(msg);
					oDialog.close();
				}
			}));
			oDialog.open();
		}