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
Mohita KalraMohita Kalra 

Pass value from one function to another ?

Hi,
I want to pass AccountId field value from init to handleRowAction function. Basically I need to set default value for Account Id in new case which I am creating from handleRowAction new case option.
This accountId value is getting returned from apex class in result variable.
({
    init: function (cmp, event, helper) {
        var actions = [{ label: 'New Case', name: 'new_Case' }];
            cmp.set('v.columns', [
            { label: 'Account Name', fieldName: 'AccountId', type: 'text' },
            { label: 'Name', fieldName: 'Name', type: 'Description' },
           { type: 'action', typeAttributes: { rowActions: actions } }
        ]);
        var action = cmp.get("c.fetchTheData"); //Calling Apex class controller 'getAccountRecord' method
             action.setParams({
                 recordId : cmp.get("v.recordId")
             });
        action.setCallback(this, function(response) {
            var state = response.getState(); //Checking response status
            var result = response.getReturnValue();
            if (cmp.isValid() && state === "SUCCESS")
                cmp.set("v.data", response.getReturnValue());  // Adding values in Aura attribute variable.   
           
        });
        $A.enqueueAction(action);
         },
    
    handleRowAction: function (cmp, event, helper) {
        var action = event.getParam('action');
        var row = event.getParam('row');

        switch(action.name) {
            case 'new_Case':
                var createRecordEvent = $A.get("e.force:createRecord");
                                createRecordEvent.setParams({
                             "entityApiName": "Case",
                                    "defaultFieldValues" : 
                                    {'AccountId' : result.AccountId}
                                    
                                    
                                     });
                                createRecordEvent.fire();
                break;
            
        }
    }
});
Sachin HoodaSachin Hooda
Hi Mohita,
You can easily pass the values from one function to another.
Please update your code.
var result = response.getReturnValue();
helper.handleRowAction(cmp, event, helper, result);
& change your method definition to accept one more variable.
handleRowAction : function(cmp, event, helper, accId){
      console.log('Account Id is-->'+accId);
}
That's it you'll be able to use the value for further operations.
____________
Regards,
Sachin
(:
{tushar-sharma}{tushar-sharma}
Hi Mohita,

You don't need to pass an extra parameter, As you are using aura:attribute to store account Id so in helper just directly use that
 
handleRowAction : function(cmp, event, helper){
      console.log('Account Id is-->'+cmp.get("v.data");
}

If this answer helps you, please mark it as accepted.

Regards,
Tushar Sharma
https://newstechnologystuff.com/