+ Start a Discussion
sen19sen19 

Unable to set attribute/var in helper.js

I am calling apex class from helper.js and want to store the return string in a var or attribute. But the return string from apex is not getting stored in any of these. Its always coming as undefined. Could anyone help me in this:

    ({
   
    helpermethd1:function(component, event, helper)
    {
        var locale = $A.get("$Locale.language");
        var returl = component.get("v.backUrl");
        console.log('returl>>>'+returl);
       
        if($A.util.isEmpty(returl) && $A.get("$Label.c.a1")===locale){
            debugger;
            
            var tokendecoded=helper.getURLParamWithoutDecode('token');
            var action=component.get("c.returl");
           
            action.setParams({"tokenSF":tokendecoded});
            action.setCallback(this, function(response){
                var state = response.getState();
                if (state === "SUCCESS"){
                    alert('success');
                    var retrnvalue=response.getReturnValue();
                    
                    if(retrnvalue!=null){
                        returl=retrnvalue;
                    }
                    else{
                        returl=$A.get("$Label.c.abc");
                    }
                }
                else
                {
                    returl=$A.get("$Label.c.abc");
                }
            });
            
            debugger;
                               
        }
        else if($A.util.isEmpty(returl)){
          
            returl = $A.get("$Label.c.xyz");
            console.log('returl UK'+returl);
           
            debugger;
        }
        $A.enqueueAction(action);
        window.open(returl,'_top');
       
   
},
   getURLParamWithoutDecode : function(identifier)
    {
        .......
        .....
    }   
   
})

Apex:
public without sharing virtual class sample {
@AuraEnabled public static String redirectURL(String tokenSF){ return abc;
Bhuvaneshwari R 1Bhuvaneshwari R 1

Hi Ananga

In your helper, in var action=component.get("c.returl");  you have mentioned the method name as "returl".

But in Apex, you have named the function as : redirectURL(String tokenSF).

Try var action=component.get("c.redirectURL"); to see if that resolves the issue.

sen19sen19
Sorry that was an tpo error. returl is there in apex as well