Andrew,
In a success event - the 'data' comes back from the API / Server call - you will see it as a parameter.
I suggest never putting a lot of code into the success event on the UI - since mappings come and go - and you don't want to lose your code.
Therefore:
in a success event - a call to a function ('runJavascript' from the mapping editor that executes BEFORE YOUR MAPPING EVENT) :
fComputeTotal( data );
In a new or existing Javascript asset (for each project our coding standard is - one Javascript file called myProjectNamePageSupportFunctions - so there is my suggestion of the day ) enter this code:
function fComputeTotal( oInboundData ){
// Objective : Sum that data that came back from our API call -
// loop through the data that came back... that was sent in the parameter...
//
// Usage: fComputeTotal( oInboundData ) - where oInboundData is data coming
// back from our Appery service collection list_plan_service
//
// Returns: True
//////////////////////////////////////////////////////////////////////////
var nCounter ;
var nLength = oInboundData.length ;
var nTotal = 0
for ( nCounter = 0, nCounter < nLength , nCounter++ ) {
nTotal += oInboundData[ nCounter ].dollars ;
console.log('The running total is: ' , nTotal ) ;
}
localStorage.nTotal = nTotal
return true ;
}
Furthermore - you should:
Create a local storage variable called nTotal
In the mapping event AFTER that Javascript event - map the localStorage variable to the UI dollars.
There are more likely 'elegant' solutions - but this is straightforward and the approach works every time. I vote for simplicity - and this is it. Apology in advance for any typos.
Best,
Bruce