<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: How to separate callback function from MessageBox. in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132043#M4533670</link>
    <description>&lt;P&gt;Use Promise for callbacks.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise&lt;/A&gt;&lt;/P&gt;&lt;P&gt; see below code&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;fnConfirmationMsg: function(sMessage, sConfirmation) {

  return new Promise((fnResolve, fnReject ) =&amp;gt; {
        MessageBox.show( sMessage, {
             title: sConfirmation,
             onClose: fnResolve
             }
        );
  });
 };

deleteRecord: function(oData) {
  this.fnConfirmationMsg("Delete data?", "Delete confirmation").then((sAction)=&amp;gt;{
        switch(oAction) {
         case "OK":
            /* do delete operation */
           break;
        default:
           break;
      })
};&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Feb 2020 09:53:20 GMT</pubDate>
    <dc:creator>BhargavaTanguturi</dc:creator>
    <dc:date>2020-02-27T09:53:20Z</dc:date>
    <item>
      <title>How to separate callback function from MessageBox.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaq-p/12132041</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
  &lt;P&gt;I am trying to create a function to delete data after user press delete button on MessageBox of confirmation.&lt;/P&gt;
  &lt;P&gt;I know that it will work following code;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;MessageBox.confirm(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: function(oAction) {
   switch(oAction) {
     case "OK":
       /* do delete operation */
       break;
     default:
       break;
 }
);&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;~~~~~~~
MessageBox.show(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: ".afterDeleteConfirmation"
);

~~~~~~

afterDeleteConfirmation: function(oAction) {
   switch(oAction) {
     case "OK":
       /* do delete operation */
       break;
     default:
       break;
 }&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Feb 2020 08:21:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaq-p/12132041</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-02-27T08:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate callback function from MessageBox.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132042#M4533669</link>
      <description>&lt;P&gt;You can create a separate function and call it from the callback. Use the reference of this but you need to assign it to another variable outside the messagebox function.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;~~~~~~~

var that=this;
MessageBox.show(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: function(oAction){
     that.afterDeleteConfirmation(oAction);
     }
);

~~~~~~

afterDeleteConfirmation: function(oAction) {
   switch(oAction) {
     case "OK":
       /* do delete operation */
       break;
     default:
       break;
 }&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Anmol&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 08:56:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132042#M4533669</guid>
      <dc:creator>former_member540067</dc:creator>
      <dc:date>2020-02-27T08:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate callback function from MessageBox.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132043#M4533670</link>
      <description>&lt;P&gt;Use Promise for callbacks.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise&lt;/A&gt;&lt;/P&gt;&lt;P&gt; see below code&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;fnConfirmationMsg: function(sMessage, sConfirmation) {

  return new Promise((fnResolve, fnReject ) =&amp;gt; {
        MessageBox.show( sMessage, {
             title: sConfirmation,
             onClose: fnResolve
             }
        );
  });
 };

deleteRecord: function(oData) {
  this.fnConfirmationMsg("Delete data?", "Delete confirmation").then((sAction)=&amp;gt;{
        switch(oAction) {
         case "OK":
            /* do delete operation */
           break;
        default:
           break;
      })
};&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Feb 2020 09:53:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132043#M4533670</guid>
      <dc:creator>BhargavaTanguturi</dc:creator>
      <dc:date>2020-02-27T09:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate callback function from MessageBox.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132044#M4533671</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;You can simplify it like this :
&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;MessageBox.show(
 "Delete data?", {
 title: "Delete confirmation",
 onClose: this.afterDeleteConfirmation.bind(this)
);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Joseph&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 06:21:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132044#M4533671</guid>
      <dc:creator>Joseph_BERTHE1</dc:creator>
      <dc:date>2020-02-28T06:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate callback function from MessageBox.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132045#M4533672</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;That's what I wanted. The progrram needs error handling for the delete operation too so that I have to make chain of Promise.&lt;/P&gt;&lt;P&gt;Your code can be used for it too.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 00:25:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132045#M4533672</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-03-03T00:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate callback function from MessageBox.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132046#M4533673</link>
      <description>&lt;P&gt;Your answer also works and I learnt how  to call function by using "that". Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 00:26:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-separate-callback-function-from-messagebox/qaa-p/12132046#M4533673</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-03-03T00:26:45Z</dc:date>
    </item>
  </channel>
</rss>

