Skip to Content


I am writing this blog to continuation of my blog Rename and Delete operation for attachment with SAP ODATA

In my previous blog I have explained, ODATA creation(backend part) for rename and delete operation,where I have implemented DELETE_ENTITY and UPDATE_ENTITY method of DPC_EXT class.


In this blog I am going to explain, how we will implement rename and delete operations for attachment in SAP UI5 (frontend logic)with uploadcollection control.Use blog Rename and Delete operation for attachment with SAP ODATA to implement ODATA logic.


Please follow my below blog for create and read odata Attachment implementation in SAP UI5(CRM and SAP UI5 integration and for delete and rename(odata backend part) Rename and Delete operation for attachment with SAP ODATA .


SAP UI5 code for rename attachment :


Please write below code in fileRenamed event of sap.m.UploadCollection .


onFileRenamed : function(oEvent){
jQuery.sap.require(“sap.m.MessageToast”);
var lComplainId =  gComplaintID;
var attachmentId = oEvent.mParameters.documentId;
var oEntry = {};

          oEntry.FileName = oEvent.mParameters.fileName;

      

        OData.request({

            requestUri : “<Server URL>/<ODATA proejct name>”,

            method : “GET”,

            headers : {           

“X-Requested-With” : “XMLHttpRequest”,

                “Content-Type” : “application/atom+xml”,

                “DataServiceVersion” : “2.0”,

                “X-CSRF-Token” : “Fetch”

                 }

            },                    

            function(data, response) {

                 header_xcsrf_token = response.headers[‘x-csrf-token’];

                 oHeaders = {

                      “x-csrf-token” : header_xcsrf_token,

                      ‘Accept’ : ‘application/json’,

                };

                          

            OData.request({

requestUri : “<Server URL>/<ODATA proejct name>/Complain_AttachmentsSet(Class=’CRM_L_ORD’,Objtype=’L’,ComplaintId='” + lComplainId + “‘,Objid='”+ attachmentId +”‘)”,
method : “PUT”,
headers : oHeaders,

                data : oEntry

               },                 

               function(data,request) {

                   loadAttachment(); // this is the funciton which loading the attachment in control

                 },        

               function(err) {

                      sap.m.MessageToast.show(“Update failed due to following Exception : “+ err);

});

                 },

                          

            function(err) {

                  var request = err.request;

                  var response = err.response;

                  sap.m.MessageToast.show(“Error in Get — Request ” + request + ” Response ” + response);

            });

}


SAP UI5 code for delete attachment :


Please write below code in fileDeleted event of sap.m.UploadCollection .


onFileDeleted : function(oEvent){
jQuery.sap.require(“sap.m.MessageToast”);
var lComplainId = gComplaintID;
var oEntry = {};

        oEntry.attachmentId = oEvent.mParameters.documentId;

        oEntry.complaintId = lComplainId;

        that = this;

        OData.request({

            requestUri : “<Server URL>/<ODATA proejct name>”,

            method : “GET”,

            headers : {

“X-Requested-With” : “XMLHttpRequest”,

                “Content-Type” : “application/atom+xml”,

                “DataServiceVersion” : “2.0”,

                “X-CSRF-Token” : “Fetch”

                }

            },                      

            function(data, response) {

                header_xcsrf_token = response.headers[‘x-csrf-token’];

                oHeaders = {

                   “x-csrf-token” : header_xcsrf_token,

                   ‘Accept’ : ‘application/json’,

                };

     

             OData.request({

requestUri : “<Server URL>/<ODATA proejct name>/Complain_AttachmentsSet(Class=’CRM_L_ORD’,Objtype=’L’,ComplaintId='” + oEntry.complaintId + “‘,Objid='”+ oEntry.attachmentId +”‘)”,
method : “DELETE”,
headers : oHeaders,

                 data : oEntry

                 },                 

                 function(data,request) {

loadAttachment();

              },        

              function(err){

sap.m.MessageToast.show(“Couldn’t Deleted due to following exception : “+ err);

              });

            },

                    

        function(err) {

                  var request = err.request;

                  var response = err.response;

                  sap.m.MessageToast.show(“Error in Get — Request ” + request + ” Response ” + response);

        });
}
To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply