Hi,
There are no errors in the Console. Neither am I loading any image in the background. PFB the screenshot and the code -
On click of upload button, handle_btnUpload is called, which in turn calls csvJSON
csvJSON : function(csv) {
var lines = csv.split("\n");
var result = [];
var flagBlankFile = 0;
for (var i = 0; i < lines.length; i++) {
var recordFound = lines[i].split(",");
if (recordFound != "") {
flagBlankFile = 1;
break;
}
}
if (flagBlankFile == 0) {
sap.ca.ui.message
.showMessageBox({
type : sap.ca.ui.message.Type.ERROR,
message : "Uploaded file is blank. Please upload a file with atleast 1 record.",
});
} else {
var headers = lines[0].split(",");
if ((headers == "")
|| (headers.length != 5)
|| (headers[0].toUpperCase().trim() != "QUARTER"
|| headers[1].toUpperCase().trim() != "YEAR"
|| headers[2].toUpperCase().trim() != "PU"
|| headers[3].toUpperCase().trim() != "TARGET" || headers[4]
.toUpperCase().replace(
/[^a-zA-Z]/g, '') != "CATEGORY")) {
sap.ca.ui.message
.showMessageBox({
type : sap.ca.ui.message.Type.ERROR,
message : "Uploaded file is not a valid .CSV file.",
});
} else {
// add additional columns which are not
// mentioned in
// excel
var colCount = headers.length;
headers[colCount] = "CreatedBy";
headers[colCount + 1] = "Active";
for (var i = 1; i < lines.length; i++) {
var obj = {};
var currentline = lines[i].split(",");
var currentlinelength = currentline.length;
if (currentline != "") {
currentline[5] = "1";
currentline[6] = "Y";
for (var j = 0; j < headers.length; j++) {
obj[headers[j]] = currentline[j]
.trim();
}
result.push(obj);
} else {
continue;
}
}
var oStringResult = JSON.stringify(result);
var oFinalResult = JSON.parse(oStringResult
.replace(/\\r/g, ""));
var requestBody = {};
requestBody.CreatedBy = '1';
// Add child to request
requestBody.NHiringTargets = oFinalResult;
var that = this;
// Issue Create
oModel
.create(
'/HiringDataCollection',
requestBody,
null,
function(oData, response) {
var oTable = that
.getView()
.byId(
"IdUploadStatusTable");
var oTemplate = new sap.m.ColumnListItem(
{
cells : [
new sap.m.Text(
{
text : "{Quarter}"
}),
new sap.m.Text(
{
text : "{Year}"
}),
new sap.m.Text(
{
text : "{PU}"
}),
new sap.m.Text(
{
text : "{Target}"
}),
new sap.m.Text(
{
text : {
path : "CreatedDate",
type : new sap.ui.model.type.Date(
{
pattern : "dd-MMM-yyyy"
})
}
}),
new sap.m.Text(
{
text : "{CreatedBy}"
}),
new sap.m.Text(
{
text : "{Category}"
}),
new sap.m.Text(
{
text : "{Active}"
}),
new sap.m.Text(
{
text : "{Status}"
}) ]
});
oTable
.setModel(new sap.ui.model.json.JSONModel(
{
data : oData.NHiringTargets.results
}));
var oBinding = oTable
.bindItems({
path : "/data",
template : oTemplate
});
//oBusyDialog.close();
},
function(oError) {
sap.ca.ui.message
.showMessageBox({
type : sap.ca.ui.message.Type.ERROR,
message : "Excel could not be uploaded due to some server issue. Please try again later.",
});
});
sap.ui.core.BusyIndicator.hide();
}
}
},