Skip to Content
0
Jul 29, 2016 at 06:53 AM

Waiting Synchronous response from a function

1702 Views

Hello everyone,

I have a requirement that I have to wait for the dialog return and close it, but I just couldnt manage it. So I would be appreciated if any of you can help me about this issue.

I have a button that triggers OnApprovePressed function and a dialog comes out.

And if the user clicks 'Approve' button then it triggers OnApproveConfirmClosed function.

THe thing is, I actually have to wait for the return from OnApproveConfirmClosed function since it connects to gateway and checks whether the document is approvable or not. And my requirement at that point is waiting for the return, closing the dialog and returning back to the master list without asking any request from the user.

As you see in my code I have already written that it should close the dialog after OnApproveConfirmClosed function. But the problem is, it does not wait for the return from the function and directly closes the dialog and returning back to the master list.

I need to wait for the function and if all the things goes well then I should be closing the dialog and returning back. If I could manage gThis from the function itself it could be possible but I dont have an idea, how can I do this.

I would be really appreciated if anyone can help me on this issue.

Thanks in advance.

Regards,

Merve

OnApprovePressed: function(evt) {

var gThis = this;

var dialog = new sap.m.Dialog({

title: 'Confirm',

type: 'Message',

content: new sap.m.Text({

text: 'Approve or decline!'

}),

beginButton: new sap.m.Button({

text: 'Approve',

press: function() {

gThis.OnApproveConfirmClosed("YES");

dialog.close();

dialog.destroy();

if (sap.ui.Device.system.phone) {

gThis.onNavBack();

}

}

}),

endButton: new sap.m.Button({

text: 'Decline',

press: function() {

dialog.close();

}

}),

afterClose: function() {

dialog.destroy();

}

});

dialog.open();

},