We'd love to hear from you! Provide  feedback  to earn a badge today. Take our quick survey
You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

Java script function return undefined

Accepted answer
10
Views
4
Comments
edited Jul 10, 2021 3:31AM in Visual Builder 4 comments

Content

Hello All,

My use case consists 1 function to call another function in js. But it keep returning undefined. 

I would like to know if i need to do a conversation or to get a work around. 

Please check sample code below and attached alert sreenshot

  PageModule.prototype.getResult1 = function () {
    var ep = Rest.get('role/getGetRole');
    var returnVal = 'Success';
    ep.fetch().then(function (result) {
      if (result.response.ok) {
        alert(result.body.count); //pass
        var resultResult = result.body.count;
        if (result.body.count == 4) {//pass
          return returnVal;// returnVal is undefined!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        }
        return 'Not OK';
      }
      else {
        return null;
      }
    });
  };
 
  PageModule.prototype.getResult1Value = function (arg1) {

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!