david.young Posted February 2, 2015 Share Posted February 2, 2015 Thanks to the example of how to work with an external data file I have been able to get the data into the template but one field,'Gift Receipt Amount', needs to show a total at the end. Attached is how the out put needs to look Thanks in advance David for (recordWalker=1; recordWalker <= numRecsExtDF; recordWalker++) { //Compare the value of the CID field in the current record //we are looking at in the external data file to the value //of the CustomerID field in the main data file. if (externalDF.GetFieldValue(recordWalker, 'Constituent ID') == Field("Constituent ID")) { //Check to see if this is a TAX item. If it is, let's format it differently //if (externalDF.GetFieldValue(recordWalker, 'Product-Purchased') == 'Tax') //{ // returnStr += '<br><b>Total Tax - ' + externalDF.GetFieldValue(recordWalker, 'Price') + '</b>'; //} //else //OK - so this is a normal product - not a Tax item { returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Date'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Type'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Amount'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Receipt Number'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Receipt Amount'); returnStr += '<br>'; } } } return returnStr;tax statements 1.pdf Quote Link to comment Share on other sites More sharing options...
step Posted February 2, 2015 Share Posted February 2, 2015 Just add a variable ("total") to hold the sum of each amount and add to it as you're stepping through the external data. My edits in red: [color="red"]var total = 0;[/color] for (recordWalker=1; recordWalker <= numRecsExtDF; recordWalker++) { //Compare the value of the CID field in the current record //we are looking at in the external data file to the value //of the CustomerID field in the main data file. if (externalDF.GetFieldValue(recordWalker, 'Constituent ID') == Field("Constituent ID")) { returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Date'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Type'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Amount'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Receipt Number'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Receipt Amount'); returnStr += '<br>'; [color="red"]total += StringToNumber(externalDF.GetFieldValue(recordWalker, 'Gift Receipt Amount').replace(/[^\d\.]/g,''));[/color] } } [color="Red"]returnStr += '<t><t><t><t>$' + FormatNumber("#.00",total);[/color] Quote Link to comment Share on other sites More sharing options...
david.young Posted February 2, 2015 Author Share Posted February 2, 2015 Thanks Step, I copied and pasted your code like this, and when I click validate I get an error "Function does not return a value" //Now, loop through all records in the external data file and //find the records that belong to the customer. This is done //by comparing the value of "CustomerID" from the main input //data file to the value of the "CID" field in the external data //file. // //Note that in this example, there can be multiple records in the //external data file for each customer which is why we are going to //look at every record in the external data file. var total = 0; for (recordWalker=1; recordWalker <= numRecsExtDF; recordWalker++) { //Compare the value of the CID field in the current record //we are looking at in the external data file to the value //of the CustomerID field in the main data file. if (externalDF.GetFieldValue(recordWalker, 'Constituent ID') == Field("Constituent ID")) { //Check to see if this is a TAX item. If it is, let's format it differently //if (externalDF.GetFieldValue(recordWalker, 'Product-Purchased') == 'Tax') //{ // returnStr += '<br><b>Total Tax - ' + externalDF.GetFieldValue(recordWalker, 'Price') + '</b>'; //} //else //OK - so this is a normal product - not a Tax item { returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Date'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Type'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Amount'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Receipt Number'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Receipt Amount'); returnStr += '<br>'; total += StringToNumber(externalDF.GetFieldValue(recordWalker, 'Gift Receipt Amount').replace(/[^\d\.]/g,'')); } } } returnStr += '<t><t><t><t>$' + FormatNumber("#.00",total); Quote Link to comment Share on other sites More sharing options...
step Posted February 2, 2015 Share Posted February 2, 2015 Well, you have to add the return to the end of it: return returnStr; Quote Link to comment Share on other sites More sharing options...
david.young Posted February 2, 2015 Author Share Posted February 2, 2015 Thanks Step, That got rid of the error. However the records return twice on the page. The data comes back as the list of donations the total and then starts over again I 'm not sure I see anything that would cause that Quote Link to comment Share on other sites More sharing options...
step Posted February 2, 2015 Share Posted February 2, 2015 Please understand that I've not seen all of the rules in your template or your data. That being said, the code that I added to your existing code wasn't meant to be copied-and-pasted and assumed to work perfectly for your job without being tweaked. It was merely an example of how I would create a variable to hold a sum of a field. It's difficult to say why it's not working for you because I haven't seen an example of the data file you're using or your template. If you collect your template and data to upload to the forum, I (or any of the other knowledgable users) can take a look for you. Quote Link to comment Share on other sites More sharing options...
david.young Posted February 2, 2015 Author Share Posted February 2, 2015 Sorry, this project has made me a little stupid. I think I've got it figured out now. Just hope the client doesn't want to change something. Thanks for your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.