cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

Hello,

I am trying to create a function to delete data after user press delete button on MessageBox of confirmation.

I know that it will work following code;

MessageBox.confirm(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: function(oAction) {
   switch(oAction) {
     case "OK":
       /* do delete operation */
       break;
     default:
       break;
 }
);

But, I want to know how to separate the callback function from the code of MessageBox as below, becasue this application needs post-processes after deletion so that the code will be longer, I think it should not be included in the code of calling MessageBox.

~~~~~~~
MessageBox.show(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: ".afterDeleteConfirmation"
);

~~~~~~

afterDeleteConfirmation: function(oAction) {
   switch(oAction) {
     case "OK":
       /* do delete operation */
       break;
     default:
       break;
 }
0 Likes
View Entire Topic
BhargavaTanguturi
Active Participant

Use Promise for callbacks.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

see below code

fnConfirmationMsg: function(sMessage, sConfirmation) {

  return new Promise((fnResolve, fnReject ) => {
        MessageBox.show( sMessage, {
             title: sConfirmation,
             onClose: fnResolve
             }
        );
  });
 };

deleteRecord: function(oData) {
  this.fnConfirmationMsg("Delete data?", "Delete confirmation").then((sAction)=>{
        switch(oAction) {
         case "OK":
            /* do delete operation */
           break;
        default:
           break;
      })
};
Former Member
0 Likes

Thank you.

That's what I wanted. The progrram needs error handling for the delete operation too so that I have to make chain of Promise.

Your code can be used for it too.