
You have a RAP Based Service Named: ZFSCM_UI_FDM_COMMENTS_O2
"dependencies": {
"@sap/ux-ui5-tooling": "1",
"@ui5/cli": "^3.0.0",
"xlsx": "^0.18.5"
}
with XXXXX have to replaced with your client details and client
server:
customMiddleware:
- name: fiori-tools-proxy
configuration:
backend:
- path: /sap
url: http://your-sap-system-url:XXXXX
client: "100"
<core:FragmentDefinition xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:core="sap.ui.core" xmlns:u="sap.ui.unified" xmlns:upload="sap.m.upload">
<Dialog id="uploadDialogSet" title="Excel Upload">
<content>
<upload:UploadSet uploadEnabled="true" id="uploadSet"
items="{path: '/', templateShareable: false}" fileTypes="xlsx, xls" maxFileNameLength="200"
beforeUploadStarts="onBeforeUploadStart" uploadCompleted="onUploadSetComplete" afterItemRemoved="onItemRemoved"
terminationEnabled="true">
<upload:UploadSetItem id="idUSI" visibleRemove="true" visibleEdit="false" fileName="{name}" url="/upload">
<upload:attributes>
<ObjectAttribute id="idOA" title="Uploaded by" text="{user}" active="false"/>
</upload:attributes>
</upload:UploadSetItem>
</upload:UploadSet>
<!-- <u:FileUploader
id="fileUploader"
name="myFileUpload"
uploadUrl="upload/"
tooltip="Upload your file to the local server"
uploadComplete="handleUploadComplete"/> -->
</content>
<buttons>
<!-- <Button id="idBtnD" text="Template" press="onTempDownload" icon="sap-icon://download-from-cloud" type="Emphasized"/> -->
<Button id="idBtnU" text="Upload" press="onUploadSet" icon="sap-icon://upload-to-cloud" type="Emphasized"/>
<Button id="idBtnC" press="onCloseDialog" text="Cancel" icon="sap-icon://cancel"/>
</buttons>
<endButton>
<Button id="idBtnClose" press=".onCloseDialog" text="Ok"/>
</endButton>
</Dialog>
</core:FragmentDefinition>
Modify the ListReportExt.controller.js (already provided) to:
sap.ui.define([
"sap/m/MessageToast",
"sap/ui/core/Fragment",
"com/sap/fscm/massupload/thirdparty/xlsx"
], function (MessageToast, Fragment, XLSX) {
"use strict";
return {
excelSheetsData: [],
pDialog: null,
onExcelUploadDialog: function () {
if (!this.pDialog) {
Fragment.load({
id: "excel_upload",
name: "com.sap.fscm.massupload.ext.fragment.ExcelUpload",
type: "XML",
controller: this,
}).then((oDialog) => {
this.pDialog = oDialog;
this.pDialog.open();
});
} else {
this.pDialog.open();
}
},
onUploadSetComplete: function (oEvent) {
var oFileUploader = Fragment.byId("excel_upload", "uploadSet");
var oFile = oFileUploader.getItems()[0].getFileObject();
var reader = new FileReader();
var that = this;
reader.onload = function (e) {
let xlsx_content = e.target.result;
let workbook = XLSX.read(xlsx_content, { type: "binary" });
workbook.SheetNames.forEach(function (sheetName) {
that.excelSheetsData.push(
XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName])
);
});
MessageToast.show("Upload Successful");
};
reader.readAsBinaryString(oFile);
},
onUploadSet: function () {
if (!this.excelSheetsData.length) {
MessageToast.show("No file selected");
return;
}
var oModel = this.getView().getModel();
var that = this;
this.excelSheetsData[0].forEach((row, index) => {
var payload = {
Customer: row["Customer ID"] || "",
CompanyCode: row["Company Code"] || "",
FiscalYear: row["Fiscal Year"] || "",
Transctn: row["Transaction"] || "",
LineItem: row["Line Item"] || "",
Notes: row["Notes"] || "",
ExcelRowNumber: index + 1
};
oModel.create("/CustomerNotes", payload, {
success: function () {
MessageToast.show("Data uploaded successfully");
},
error: function (error) {
console.error(error);
}
});
});
this.pDialog.close();
},
onCloseDialog: function () {
this.excelSheetsData = [];
this.pDialog.close();
}
};
});
"dataSources": {
"mainService": {
"uri": "/sap/opu/odata/sap/ZFSCM_UI_FDM_COMMENTS_O2/",
"type": "OData",
"settings": {
"odataVersion": "2.0"
}
}
}
Bind it to a model:
"models": {
"": {
"dataSource": "mainService",
"settings": {
"defaultBindingMode": "TwoWay"
}
}
}
Run the App Locally
Run Commands in Console.
npm install
npm run start
npm run build
fiori deploy --config ui5-deploy.yaml
✅Upload Excel File
✅Parse Excel Data using xlsx.bundle.js
✅Send Data to OData V2 Service
✅Handle Upload Completion & Errors
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
23 | |
23 | |
22 | |
15 | |
14 | |
9 | |
8 | |
8 | |
7 | |
6 |