Technology Blog Posts by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
gerd_schoeffl
Product and Topic Expert
Product and Topic Expert
2,163

End User File Upload

In 2024 we shipped the end user file upload in SAP Analytics Cloud planning (see New End User File Upload in SAP Analytics Cloud QRC3 2024). The feature has been well received by our customers and in widely adopted now. Since then we have been working on enhancing the feature (see New Clean and Replace Feature for SAC End User File Upload ) but also still see areas where we can improve, like the necessity to provide a more flexible un-pivoting (see also How to configure a dynamic file upload in SAP Analytics Cloud).

With version SAC QRC1 2026 we provide a new script event, that allows customers to check and massage the uploaded data before it is written into the system and to control error situations flexibly. 

Events in File Upload

So far we had two JavaScript events in the file upload: onBeforeExecute and onAfterExecute. The event onBeforeExecute is executed before any of the upload functions is performed whereas onAfterExecute is triggered when everything has finished already. Customer have been asking for an additional event that is triggered during the upload. This event is now delivered with SAC QRC1 2026 and is called onBeforeImport.

Events.png

 

When is the Event Called? Which information does it receive?

When running a file upload from the file upload starter the user is asked to select the file in a file selector. Once a file has been chosen the content of the file is uploaded to the browser. 

This is the moment the new event is triggered. In your script you have access to the following information:

  • file name of the chosen file (fileName),
  • the content of the file (fileContent),
  • the target version where the data should be written,
  • value of flag for using the first row as headers (firstRowAsHeaders).

The JavaScript can return the object DataUploadFileHandler. In this object you can set two parameters:

  • continue
  • modifiedFileContent.

How can you react?

The first parameter enables you to abort the file upload. By default the value is set to 'true'. If you set the parameter continue to 'false', then the file upload will be stopped.

The second parameter can contain the modified file content. If you leave this parameter blank, then the system will use the originally uploaded data for further processing. In case the parameter is filled, the system will continue with the new content. That means that in your JavaScript you have the option to not only check the uploaded data but even massage the data before further processing. For example, you could:

  • eliminate erroneous records,
  • correct erroneous records,
  • do dynamic un-pivoting, etc.

Please note that you will receive the data as uploaded with no mappings defined in data wrangling applied yet.

Provided that you do not abort the execution by setting the parameter continue to 'false' the system now proceeds with processing the data. The system will check whether a new file content has been provided - in this case it will proceed with the new content. If no new content has been provided, then the system proceeds with the unaltered initially uploaded content.

The data records are then sent to the data wrangling where all the mappings defined in the definition of the job are applied. Finally the data is checked and the correct data is written to the model.

Sample Coding

We want to give a simple example here. Let us assume we are uploading a file with header line (first row of the file consists of the column headers).

This is our sample coding in our script:

 
//1. send an information with the name of the uploaded file
Application.showMessage(ApplicationMessageType.Warning, "Uploaded file name is" + fileName );
 
//2. show the content of the uploaded file in the console
for (var i=0;i<fileContent.length;i++){
var lineTest = fileContent[i];
console.log(lineTest);
}
 
//3. massage the uploaded file and only use the first 7 rows (including one header row) for the upload
var UpdatedFile = fileContent.splice(0,7);
var result = cast(Type.DataUploadFileHandler,{continue:true, modifiedFileContent:UpdatedFile});
return result;

In the first block we show an example, how to use the file name of the uploaded file and to display it to the end user (as a warning).

In the second block we show how to access the content of the uploaded file. We loop over the rows and display each row in the console.

In the last block we show how the uploaded data can be modified. We use a modified file content containing only the first 7 rows of the originally uploaded data. As the first row contains the header line we thus only us the first 6 data records from the original file.

Let us run the sample upload with the above script. We trigger the upload starter that is using our script. After our selected file is uploaded to the browser, we get the information which file has been selected.

event 1.png

 Next, we have a look at the console and can view the content of the uploaded data. Our uploaded file contains 10 data records.

Event 2.png

And finally, once the upload has finished, we get the information that 6 new records have been written into the selected version.

event3.png

Thus we can see that indeed the modified data was used that we have stripped down to 6 records (plus the header line).

3 Comments