Please see controller code provided
({
doInit : function(component, event, helper) {
// define recordid
var recordId = component.get("v.recordId");
// Create actions
var action1 = component.get("c.getShipmentCost");
action1.setParams({ wamshipment : recordId });
var action2 = component.get("c.getFulfillmentCost")
action2.setParams({ wamshipment : recordId });
// Add callback behavior
action1.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.shipmentcost", response.getReturnValue());
} else {
console.log("Failed with state: " + state);
}
});
action2.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.fulfillmentCost", response.getReturnValue());
// Call function to calculate third variable
calculateTotal();
} else {
console.log("Failed with state: " + state);
}
})
// Send actions to be executed
$A.enqueueAction(action1);
$A.enqueueAction(action2);
},
calculateTotal: function(component, event, helper) {
var scost = component.get("v.shipmentcost");
var fcost = component.get("v.fulfillmentcost");
var total = fcost + scost;
component.set("v.totalcost", total);
}
})
(I wouldn't be opposed to moving the functions in the init function to the helper, I just want to get this to work first).
Any help is greatly appreciated!Thanks!