You need to sign in to do that
Don't have an account?
Mohita 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;
}
}
});
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;
}
}
});
You can easily pass the values from one function to another.
Please update your code. & change your method definition to accept one more variable. That's it you'll be able to use the value for further operations.
____________
Regards,
Sachin
(:
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
If this answer helps you, please mark it as accepted.
Regards,
Tushar Sharma
https://newstechnologystuff.com/