- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 11:39 PM - edited 10-19-2023 11:44 PM
When user clicks on a button, I have invoked a client side function which is making a server function call using c.server.get, but its not waiting for the response from server side.
I checked using alert and can confirm that the server function is returning true/false but the client side function test() is returning undefined since its not waiting for server function to return response.
if(test()){
logic 1
} else {
logic 2
}
//Client side function
function test(){
c.server.get({
action: "checkIssue"
}).then(function(response) {
return response.data.checkIssueVar;
});
}
//Server side function
if (input.action == 'checkIssue') {
//some logic
return data.checkIssueVar;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:47 AM
Please check article: https://stackoverflow.com/questions/34094806/return-from-a-promise-then, you will need to understand how does promise work then you will know how to rectify your code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:37 AM - edited 10-20-2023 12:41 AM
function test() {
c.server.get({
action: "checkIssue"
})
.then(function (response) {
if(response.data.checkIssueVar){
logic 1
}
else{
logic 2
}
});
}
test();
Basically the issue you are facing is a typical javascript promise issue, please refer to this article to understand how does it work: https://stackoverflow.com/questions/34094806/return-from-a-promise-then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:44 AM - edited 10-20-2023 12:45 AM
Though this could have been a possible solution but unfortunately this wont do, since the logic that I have to run is also dependent on other functions, PSB:
if(test() && test2() && test3()){
logic1;
}else{
logic2;
}
For ease of understanding I had shown 1 function call in the example I had shared earlier:
Now in this case since my other function always returns undefined at first, hence the else part runs always
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:47 AM
Please check article: https://stackoverflow.com/questions/34094806/return-from-a-promise-then, you will need to understand how does promise work then you will know how to rectify your code