+ Start a Discussion
Moshe BaitelmanMoshe Baitelman 

Process results of a callback function after response

Building my first Lightning component to go on a record details page in Communities.

I have to calculate 3 values. 2 are calculated in the doInit function in the controller with callback functions. The third is the sum of the first two.

I tried writing another function to calculate the 3rd value, calling that function in the callback response but I get an error that the function is not defined. 
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
            } else {
                console.log("Failed with state: " + state);
        // Send actions to be executed
    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!

Zane AileenZane Aileen
A callback function is a function that you pass to someone and let them call it at some point of time. I think people just read the first sentence of the wiki definition: a callback is a reference to executable code, or a piece of executable code, that is passed as an argument to other code lite blue (https://liteblue.me).
Gregory ByronGregory Byron
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.TCS( https://tcswebmail.co/)
Ansh MalikAnsh Malik
To solve out you must define the value of 2nd and 3rd functions. I still got the error as call back function is a function that is to be executed after another function has finished executing — hence the name ‘call back’.I  tried this on this website (http://watchallanime.com/ (https://watchallanime.com)) but after executing another function.
vinnie kafevinnie kafe
If we run the code multiple times, we may get different results each time. ... The only way to schedule code after promise , is to attach a callback via then . 
devin cafedevin cafe
GoGPayslip is an online electronic payslip entryway intended for government representatives in Ghana. The Government of Ghana electronic payslip offers changed preferences of the old printed copy payslips.

devin cafedevin cafe
friends if you looking for the Old Navy near Me location, so you have two option, you can visit the Old Navy official site.
ki ftki ft
flower, sometimes known as a bloom or blossom, is the reproductive structure found in flowering plants (plants of the division Magnoliophyta,
tcs webmailtcs webmail
TCS Webmail (https://tcsmail.website/) – Tata Consultancy companies or TCS is Consultancy office who best in their field and do awesome work for their client..
halak desaihalak desai
UIDAI Aadhar Card Download Online (https://uidaiaadharcard.online/)– We provide an informative helpful guide about UIDAI Aadhar Card and many other facilities related to Aadhar Card. aadhar card download by name and date of birth (https://uidaiaadharcard.online/download-e-aadhar-card-by-date-of-birth-dob-and-name/)
jhon smith 16jhon smith 16
Mystic Messenger Emails (https://mysticmessengeremails.com) - Here we are provide all information. So Enjoy this article.Mystic Messenger emails guide page you’ll find correct answers to email
kishan suklakishan sukla
Bank Customer Care Numbers (https://bankguideonline.com/) - Find All Indian Bank Customer Care Toll Free Numbers and complain number. Also, Find how to check account balance by missed call alert and SMS.
nbi clearance onlinenbi clearance online
NBI Clearance Online (https://nbiclearanceonline.website/) Application and Renewal are the most topic on this website. To give the best answer to your question regarding the NBI Clearance issue.
iob netbankingiob netbanking
IOB NET BANKING (https://www.iobnetbanking.website/) - Follow these simple steps to register on IOB internet banking mentioned.
njmc directnjmc direct
NJMCDirect (https://njmcdirect.us/) Traffic Tickets Online Payment at official website ere To know and Pay Traffic Ticket In Easily & Also Get More Benefits and Features.
cad logincad login
USA banking and insurance login Information (https://cardlogin.us/) - Describe how to use online banking and insurance systems.
all infoall info
Allinfo.us (https://allinfo.us/) is really a blog that focuses on providing useful and relevant guides and knowledge on acquiring Trending News, Banking Information, Social News.
sean parker 38sean parker 38
In computer programming, a callback, also known as a "call-after" function, is any executable code that is passed as an argument to other code; that other code is expected to call back (execute) the argument at a given time. This execution may be immediate as in a synchronous callback, or it might happen at a later time as in an asynchronous callback. Programming languages support callbacks in different ways, often implementing them with subroutines, lambda expressions, blocks, liteblue (https://liteblueuspsblog.blogspot.com/2020/03/liteblue-usps-login-to-liteblueuspsgov.html) or function pointers.
bank tollfreebank tollfree
Find All Indian Bank Customer Care Toll Free Numbers and complain number (https://banktollfree.xyz). Also, Find how to check account balance by missed call alert
cora dieselcora diesel
So, it is always advised to check the balance of one’s prepaid card in the portal for PrepaidCardStatus (https://prepaidcardstatus.club/). For doing this, we have to log in to the very portal with our security code and the card number. 
mysticmessenger onlinemysticmessenger online
Mystic Messenger Guide will provide you with all the information you want to know about this dating simulation app. Find out what's in it for you! Mystic Messenger (https://mysticmessenger.online/)
faina buffetfaina buffet
Thanks for sharing these stuff with us.(https://azpayslips.co.uk/mymorri-payslip/)
becu onlinebecu online
Becu Guide Tutorial of how you manage Becu Login,Becu hours,Becu routing number,Becu near me,becu online banking, becu customer service - Becu (https://becuguide.online)
Pintu Pintu 4Pintu Pintu 4
Wеll, tоdау I gоt уоu соvеrеd wіth the аnѕwеrѕ thаt wіll hеlр уоu to раrtісіраtе іn thе Foot Action Guest Feedback Survey.