Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
namas1994
Advisor
Advisor



Links to other blogs post in this series -

  1. Excel Upload using RAP: Part - 1

  2. Excel Upload using RAP: Part - 2

  3. Excel Upload using RAP: Part - 3






Introduction


In continuous to the previous blog post (Excel Upload using RAP: Part -1 | SAP Blogs), where I have discussed about the creation of an basic OData service using RAP Model.

This is the second part of 3 blog post series, to develop a solution on uploading data to custom database table using SAP RAP Model using the Fiori Interface.

In this blog post, we will be creating a Fiori Elements application using the tools provided in SAP Business Application Studio (BAS).

Here I will be using the SAP BTP Trial Account for creating this Application




Prerequisites



  • SAP Business Application Studio in your respective BTP Trial Account

  • Basics of using the Fiori Element App Generator Extension

  • Fragments in SAPUI5

  • Using UploadSet Control


Note: You also can use the File Uploader control for uploading the file. I am using the UploadSet Controller for learning purpose only.




Lets first initialize the Fiori Application using the Fiori App Generator in SAP Business Application Studio -

The below video shows steps involved in generating the App -






Lets Start !!!


Once the basic app has been generated, then we will be using Fiori Guided Development tools to add an Custom Button "Excel Upload". Step for adding a custom button to the app -

Step - 1: Right Click on Project Folder, and click on Open Guided Development.


Step - 2: Choose "Add Custom action to a page option".


Step - 3: Click on Step 1, give an JS function name, this function will be called when you click on the Custom button. and then click on Insert Snippet followed by Next button


Step - 4: in the Step 2 to tab, select the button position, button id & button text and then click on
insert snippet and exit the guide.


Step - 5: After completing the above mentioned in steps, the below method codes will be inserted in the respective place.


Step - 6: Create a new fragment ExcelUpload.fragment.XML in the folder ext\fragment, add the SAPUI5 Control UploadSet, which will be used for uploading the file.
<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 visibleRemove="true" visibleEdit="false" fileName="{name}" url="/upload">
<upload:attributes>
<ObjectAttribute title="Uploaded by" text="{user}" active="false"/>
</upload:attributes>
</upload:UploadSetItem>
</upload:UploadSet>
</content>
<buttons>
<Button text="Template" press="onTempDownload" icon="sap-icon://download-from-cloud" type="Emphasized"/>
<Button text="Upload" press="onUploadSet" icon="sap-icon://upload-to-cloud" type="Emphasized"/>
<Button press="onCloseDialog" text="Cancel" icon="sap-icon://cancel"/>
</buttons>
<endButton>
<Button press=".onCloseDialog" text="Ok"/>
</endButton>
</Dialog>
</core:FragmentDefinition>

Step - 7: Adding button press event handler for the button present in the UploadSet control in the file ListReportExt.controller.js
sap.ui.define(["sap/ui/core/Fragment"],
function (Fragment){
"use strict";
return {
openExcelUploadDialog: function(oEvent) {
var oView = this.getView();
if (!this.pDialog) {
Fragment.load({
id: "excel_upload",
name: "v2.pgms.building.ext.fragment.ExcelUpload",
type: "XML",
controller: this
}).then((oDialog) => {
var oFileUploader = Fragment.byId("excel_upload", "uploadSet");
oFileUploader.removeAllItems();
this.pDialog = oDialog;
this.pDialog.open();
})
.catch(error => alert(error.message));
} else {
var oFileUploader = Fragment.byId("excel_upload", "uploadSet");
oFileUploader.removeAllItems();
this.pDialog.open();
}
},
onUploadSet: function(oEvent) {
console.log("Upload Button Clicked!!!")
/* TODO:Call to OData */
},
onTempDownload: function (oEvent) {
console.log("Template Download Button Clicked!!!")
/* TODO: Excel file template download */
},
onCloseDialog: function (oEvent) {
this.pDialog.close();
},
onBeforeUploadStart: function (oEvent) {
console.log("File Before Upload Event Fired!!!")
/* TODO: check for file upload count */
},
onUploadSetComplete: function (oEvent) {
console.log("File Uploaded!!!")
/* TODO: Read excel file data*/
},
onItemRemoved:function (oEvent) {
console.log("File Remove/delete Event Fired!!!")
/* TODO: Clear the already read excel file data */
}
};
});





Application Preview (after step 5)


Now right click on the project folder to preview the application -


On click of the button, the below popup is getting displayed.







Application Preview


Run the Application in preview mode -



On Click of the Excel Upload button you can see the opening of the ExcelUpload fragment







Conclusion


And there you have learned how to create a Fiori Application with a Custom Action Button on the list report and also opening the fragment in which the UploadSet Control has been implemented.

Thanks for reading this post, I would like to read your thoughts in the comments !!!

In the next blog post, we will be implementing the excel upload logic to the Custom Action Button (Upload).

 
14 Comments
former_member494196
Discoverer
0 Kudos
Looking forward to your update!!!
0 Kudos
Hello @namas1994,

 

Any update on the Part-3 of this Excel upload blog. I have the same requirement.

 

Regards,

Rajesh Maripeddi
0 Kudos
Hi @namas1994,

 

Please update the part 3 of this Excel upload blog..Exactly the same requirement I have in my project.

 

Regards,

Manish Gupta
namas1994
Advisor
Advisor
0 Kudos
Hi rajesh.maripeddi jax_liuxiaoyu simran1011,

 

Apologies for the delay I have published the Part 3 of blog post series.

Please have a look, let me know you thoughts on this.

 

Regards,

Namasivayam
0 Kudos
Hello namas1994

Thanks for the update. Very nice blog.

The challenge I can see in this, this will read the each line and then update to backend but if we upload the file with many record then then there will be chance of failure or time consuming. For small number of entries it will work fine.

Secondly, you have used the third party library xlsx which in most of our client will not agree upon.

What we did in our project, we have developed a backend transaction for file upload and then that transaction we have call on button click as a popup via assigning in target mapping.

As the whole program runs in back ground, with our huge data seems there could not be much chances of failure or load on system due to to n from between UI and Backend.

Yes we have face some challenges related to hiding some of the backend buttons.

Please add some comments or thought on our approach.

Appreciate your work.

Thanks,

Rajesh Maripeddi

 

 

 

 

 

 
namas1994
Advisor
Advisor
Hi rajesh.maripeddi

Thank you!!!

I agree that for bulk data upload, there might be some chances of failure which I need to test.

Also my thoughts on writing this blog post was to do the excel file reading in the browser and send the read data to the backend for processing.

As I can see that in your implementation you are using background processing for excel processing which is also an another way of doing it(Yes) and which I did not thought of.

Regards,
Namasivayam
shavneet1
Participant
0 Kudos
Hello Rajesh ,

That's  a Nice Approach.

We have kind of similar requirement. Uploading data in the master lost from the Excel.

and we want to Do it completely from the backend Side.

Can you please me with your code Snippets , how you were able to achieve this.

 

Thanks and Best Regards ,

Shavneet Singh
shavneet1
Participant
0 Kudos
Hello Rajesh ,

 

Could you please reply.

 

Thanks and Regards ,

Shavneet Singh
JulT
Explorer

Hi namas1994 ,

I did your Tutorial, but my events of the Fragment won't Trigger... Do you have any Idea what I did wrong?

Best wishes,

Julian

 

Edit: Solved by using explicitly mentioning the handler in my fragmentView.

<Button core:require="{ handler: 'my/domain/myApp/controller/CustomActionHandler'}" id="BtnSuccess" press="handler.onSuccessClose" text="Success" icon="sap-icon://accept" type="Success"/>
0 Kudos
Hi namas1994 ,

Thank you for sharing this blog, this is very helpful. I tried the excel upload option and it worked just fine when I test run the app via SE80, however when I try to open the app via Fiori tile its giving the following error. Have you faced this issue as well? Any help will be greatly appreciated.

Target was not found. Cannot read properties of undefined (reading 'getMetadata') Error

I have raised a question in the forum as well. Please refer to the below link for more details.

https://answers.sap.com/questions/13971875/target-was-not-found-cannot-read-properties-of-und.html

 

Regards

Geet
0 Kudos
Hi,

Was able to resolve the xlsx issue by performing the following steps in vscode.

  • rename the fragment to *.xml (XML to lowercase)

  • copy the xlsx.js file to your ext folder:




  • adjust your controller:


DiegoValdivia
Participant

Thanks for this excellent post!

Just for anyone implementing this code. There are two errors in the post which need to be fixed:

1.- Fragment file name must be ExcelUpload.fragment.xml instead of ExcelUpload.fragment.XML (xml extension must be lower case)

2.- The fragment name set in the controller must be pgmsbuildingv2.ext.fragments.ExcelUpload instead of v2.pgms.building.ext.fragment.ExcelUpload

This is the file tree, in case it helps.

DiegoValdivia_0-1710473534142.png

 

meenakshi-btp
Explorer
0 Kudos

@namas1994 Thanks for the excellent blog series. We have a similar requirement in my project where I am trying to add the Excel upload functionality in my RAP based app.

I get the following error, when I click on the Excel Upload button:

meenakshibtp_0-1711052745113.png

 

As suggested by @DiegoValdivia , I changed the fragment name set in the controller, but no luck. Any pointers are greatly appreciated.

Former Member
0 Kudos

For all those Who are getting the error related to 'file not found'. Make changes in your file path in controller. it should be {projectname}/ext/fragment/{name-of-fragment}.

See i have not given webapp, it is not considering/triggering webapp. 

Name your folders ( fragment, controller )  correctly.

Thanks 🙂

Considering You have changed the fragment extention from XML to lower case .xml

@meenakshi-btp 

Labels in this area