function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ArunaAruna 

How to call one helper or controller function variables or results into another funcation

Hi I need to access the helper2 variable in the helper1 method for example
 
Sample apex class

Public class SampleApexCls{


 @AuraEnabled
  public static List<String> testSmapleMethod(){
     //some code here
      Return ListofValues;
   }
 @AuraEnabled
  public static Map<Id,String> testSmapleMethod2(){
     //some code here
      Return map;
   }

}
 
({
	getSmapleData :function(component){

        var action=component.get("c.testSmapleMethod");
		action.setCallback(this,function(response){
			var returnValue=response.getReturnValue();
		
                     this.getSmapleData1 (component) // I know how to call the funcation
                   // Whant to get "returnValue2" results in this method.

		});

	},
	getSmapleData1 :function(component){
		var action=component.get("c.testSmapleMethod2");
		action.setCallback(this,function(response){
			var returnValue2=response.getReturnValue();
		
		});
	}
})
how do I access "returnValue2" in  "getSmapleData"  funcation.
can  "getSmapleData1" return some value.

can any please help to get the one funcation values or varaible to display in other funcation like how we do in general apex class

 
Naveen KNNaveen KN
Hi Aruna, 

I don't think we have an option to call one method in another method within the controller, whereas we can do that inside the helper bundle. 

Find the working code and modify based on your requirements 

Component: 
<aura:component implements="flexipage:availableForAllPageTypes">
    <aura:handler name='init' value='{!this}' action='{!c.doInit}' />
</aura:component>
Controller js file:
({
    doInit  : function(component, event, helper) {
		helper.getSampleData1(component, event, helper);
    },
})
Helper js file:
({
    getSampleData  : function(returnValue2) {
        console.log('inside getSampleData');
        console.log(returnValue2);
    },
    getSampleData1  : function(component, event, helper) {
        var returnValue2 = "My custom test value!"; 
        helper.getSampleData(returnValue2);
    },
})

Output in the browser console:
User-added image

Test this and share the results. 

Naveen
Team codengine.in