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
Sumesh ChandranSumesh Chandran 

Pass values from controller.js to helper.js!

Hello all,
Totally new to Javascript.
I am trying to pass values from the controller.js to the helper.js file. Here in the below code I am trying to pass the 'selectedRecordId' and the 'selectedButtonLabel' variable to the helper.js file. Not sure how to do it in JS.

Here is my controller code:
({
   handleRowAction :function(component, event, helper){
       var selectedButtonLabel = event.getSource().get("v.label");
        var selectedRecordId = event.getSource().get("v.value");
        helper.updateOppStage(component, event, helper);
  }
})
Here is my helper code:
({   
    updateOppStage : function(component, event, helper) {
        var action = component.get("c.findById");
    }
})
Here is my apex code:
public class OppsListApexController {
    @AuraEnabled
    public static Opportunity findById(String oppId) {
        return [select Name, CloseDate, StageName, sumchans__OppOwner__c from Opportunity where id=:oppId];
    }
}


Please advise!

Thanks
Best Answer chosen by Sumesh Chandran
Raj VakatiRaj Vakati
Try this code


Controller
 
({
   handleRowAction :function(component, event, helper){
       var selectedButtonLabel = event.getSource().get("v.label");
        var selectedRecordId = event.getSource().get("v.value");
        helper.updateOppStage(component, event, helper ,selectedButtonLabel , selectedRecordId);
  }
})

helper
 
({   
    updateOppStage : function(component, event, helper , selectedButtonLabel ,  selectedRecordId) {
        var action = component.get("c.findById");
		 action.setParams(
            {
                oppId : selectedRecordId
            }
        );
      
        action.setCallback(this, function(response) {
            var state = response.getState();
            
             if (state === "SUCCESS") {
                    
            }

        });
        $A.enqueueAction(action);
    }
})

 

All Answers

Raj VakatiRaj Vakati
Try this code


Controller
 
({
   handleRowAction :function(component, event, helper){
       var selectedButtonLabel = event.getSource().get("v.label");
        var selectedRecordId = event.getSource().get("v.value");
        helper.updateOppStage(component, event, helper ,selectedButtonLabel , selectedRecordId);
  }
})

helper
 
({   
    updateOppStage : function(component, event, helper , selectedButtonLabel ,  selectedRecordId) {
        var action = component.get("c.findById");
		 action.setParams(
            {
                oppId : selectedRecordId
            }
        );
      
        action.setCallback(this, function(response) {
            var state = response.getState();
            
             if (state === "SUCCESS") {
                    
            }

        });
        $A.enqueueAction(action);
    }
})

 
This was selected as the best answer
Sumesh ChandranSumesh Chandran
Thanks Raj, that worked!