Subject of Email Should changed based on Cell Value - javascript

I have created a Google script to send an email once the user submits the form. The script is running very well. But one thing that is not proper is the subject of the email. I want the email subject to be changed based on the cell value.
Currently, I am using this script:
function afterFormSubmit(e) {
const info = e.namedValues;
const pdfFile = createPDF(info);
const entryRow = e.range.getRow();
const ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Final Responses");
ws.getRange(entryRow, 64).setValue(pdfFile.getUrl());
ws.getRange(entryRow, 65).setValue(pdfFile.getName());
sendEmail(e.namedValues ['Email address'][0],pdfFile);
}
function sendEmail(email,pdfFile){
var DOR = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Final Responses").getActiveCell();
var NOO = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Final Responses").getActiveCell();
var subject = "DTR - KCCO - " + NOO + " - " + DOR;
var body = "Sir," + String.fromCharCode(10)+ String.fromCharCode(10) + "Please find the attached Daily Transaction Report for the outlet " + NOO + " for " + DOR + "." + String.fromCharCode(10) + String.fromCharCode(10)+ "--" + String.fromCharCode(10) + "Thanks & Regards" + String.fromCharCode(10) + "KCCO - Automation Team" ;
GmailApp.sendEmail(email, subject, body, {
attachments: [pdfFile],
name: 'KCCO - Automation Team'
});
}
function createPDF(info) {
const pdfFolder = DriveApp.getFolderById("1ME3EqHOZzBZDBLNPHQxLjf5tWiQpmE8u");
const tempFolder = DriveApp.getFolderById("1ebglel6vwMGXByeG4wHBBvJu9u0zJeMJ");
const templateDoc = DriveApp.getFileById("1kyFimRMdHQZV85F5P6JyCHv1DQ3KJFv1hx5o7lIcNZo");
const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
body.replaceText("{Name of Person}", info['Name of Person'][0]);
body.replaceText("{Date of Report}", info['Date of Report'][0]);
body.replaceText("{Name of Outlet}", info['Name of Outlet'][0]);
body.replaceText("{Opening Petty Cash Balance}", info['Opening Petty Cash Balance'][0]);
body.replaceText("{Total Petty Cash Received}", info['Total Petty Cash Received'][0]);
body.replaceText("{Closing Petty Cash Balance}", info['Closing Petty Cash Balance'][0]);
body.replaceText("{Total Petty Cash Paid}", info['Total Petty Cash Paid'][0]);
body.replaceText("{Available Float Cash Balance}", info['Available Float Cash Balance'][0]);
body.replaceText("{Milk for Outlet}", info['Milk for Outlet'][0]);
body.replaceText("{Cold Drink And Ice Cube Purchased}", info['Cold Drink And Ice Cube Purchased'][0]);
body.replaceText("{Goods Purchased for Outlet}", info['Goods Purchased for Outlet'][0]);
body.replaceText("{Staff Milk/Toast etc.}", info['Staff Milk/Toast etc.'][0]);
body.replaceText("{Water Tank Charges}", info['Water Tank Charges'][0]);
body.replaceText("{Repair And Maintenance}", info['Repair And Maintenance'][0]);
body.replaceText("{Petrol Expenses}", info['Petrol Expenses'][0]);
body.replaceText("{Freight Paid}", info['Freight Paid'][0]);
body.replaceText("{Purchase of Soya Chaap}", info['Purchase of Soya Chaap'][0]);
body.replaceText("{Purchase of Rumali Roti}", info['Purchase of Rumali Roti'][0]);
body.replaceText("{Purchase of Egg Tray}", info['Purchase of Egg Tray'][0]);
body.replaceText("{Other Expenses}", info['Other Expenses'][0]);
body.replaceText("{Please Specify Other Expenses}", info['Please Specify Other Expenses'][0]);
body.replaceText("{Total Tip Amount PAYTM & CARD}", info['Total Tip Amount PAYTM & CARD'][0]);
body.replaceText("{Cash Sales - Outlet}", info['Cash Sales - Outlet'][0]);
body.replaceText("{Cash Sales - KCCO App}", info['Cash Sales - KCCO App'][0]);
body.replaceText("{Card Sales}", info['Card Sales'][0]);
body.replaceText("{Credit/Udhar Sales}", info['Credit/Udhar Sales'][0]);
body.replaceText("{Paytm Sales}", info['Paytm Sales'][0]);
body.replaceText("{KCCO App Sales Razor Pay}", info['KCCO App Sales Razor Pay'][0]);
body.replaceText("{Swiggy Sales}", info['Swiggy Sales'][0]);
body.replaceText("{Zomato Sales}", info['Zomato Sales'][0]);
body.replaceText("{Dunzo Sales}", info['Dunzo Sales'][0]);
body.replaceText("{Zomato Gold Sales}", info['Zomato Gold Sales'][0]);
body.replaceText("{Dine Out Sales}", info['Dine Out Sales'][0]);
body.replaceText("{Total Cancelled Bill Amount}", info['Total Cancelled Bill Amount'][0]);
body.replaceText("{Total Sales of the Day - Total of Above}", info['Total Sales of the Day - Total of Above'][0]);
body.replaceText("{Total Sales of the Day - As Per PetPooja}", info['Total Sales of the Day - As Per PetPooja'][0]);
body.replaceText("{Old Due Receipts - Cash}", info['Old Due Receipts - Cash'][0]);
body.replaceText("{Old Due Receipts - Other Modes}", info['Old Due Receipts - Other Modes'][0]);
body.replaceText("{Tip Receipts - Card}", info['Tip Receipts - Card'][0]);
body.replaceText("{Tip Receipts - Paytm}", info['Tip Receipts - Paytm'][0]);
body.replaceText("{Currency Note of INR 2000}", info['Currency Note of INR 2000'][0]);
body.replaceText("{Currency Note of INR 500}", info['Currency Note of INR 500'][0]);
body.replaceText("{Currency Note of INR 200}", info['Currency Note of INR 200'][0]);
body.replaceText("{Currency Note of INR 100}", info['Currency Note of INR 100'][0]);
body.replaceText("{Currency Note of INR 50}", info['Currency Note of INR 50'][0]);
body.replaceText("{Currency Note of INR 20}", info['Currency Note of INR 20'][0]);
body.replaceText("{Currency Note of INR 10}", info['Currency Note of INR 10'][0]);
body.replaceText("{Other Currency Note/Coins}", info['Other Currency Note/Coins'][0]);
body.replaceText("{Total Available Cash to Handover}", info['Total Available Cash to Handover'][0]);
body.replaceText("{Total No. of Credit Bills}", info['Total No. of Credit Bills'][0]);
body.replaceText("{S.No.//Name of Person// Mobile No// Credit Approval By// Bill No// Total Amount of Credit}", info['S.No.//Name of Person// Mobile No// Credit Approval By// Bill No// Total Amount of Credit'][0]);
body.replaceText("{Total No. of Bills of Credit Recovery}", info['Total No. of Bills of Credit Recovery'][0]);
body.replaceText("{S.No.//Name of Person// Mobile No// Mode of Payment// Bill No// Total Amount Received}", info['S.No.//Name of Person// Mobile No// Mode of Payment// Bill No// Total Amount Received'][0]);
body.replaceText("{Total No. of Complementary Bills During the Day}", info['Total No. of Complementary Bills During the Day'][0]);
body.replaceText("{S.No.//Name of Person// Mobile No//Reason// Bill No//Amount Settled}", info['S.No.//Name of Person// Mobile No//Reason// Bill No//Amount Settled'][0]);
body.replaceText("{Total No. of Cancelled Bills During the Day}", info['Total No. of Cancelled Bills During the Day'][0]);
body.replaceText("{S.No.//Name of Person// Mobile No// Bill No// Bill Amount}", info['S.No.//Name of Person// Mobile No// Bill No// Bill Amount'][0]);
body.replaceText("{S.No.// Bill No// Mode of Payment//Tip Amount Received}", info['S.No.// Bill No// Mode of Payment//Tip Amount Received'][0]);
body.replaceText("{No. of Cylinders Received at Outlet}", info['No. of Cylinders Received at Outlet'][0]);
body.replaceText("{Timestamp}", info['Timestamp'][0]);
body.replaceText("{Email address}", info['Email address'][0]);
//body.replaceText("{Total of Cash Denomination}", info['Total of Cash Denomination'][0]);
openDoc.saveAndClose();
const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName('DTR - KCCO - '+info['Name of Outlet'][0]+ " - " + info['Date of Report'][0]);
tempFolder.removeFile(newTempFile);
return pdfFile;
}
The link of the Response submitted by a Google form is as below:
https://docs.google.com/spreadsheets/d/1m6Aca0TcLf5UZ7P9CvAdQDokoazQljsqDT6CGh0K3j4/edit?usp=sharing
I want the Name of the Outlet i.e. F2:F
and Date of Report i.e. C2:C
E.g. if the user submits the form now data will appear in the 37th row so the name of the outlet and report should be F37 and C37.
Please guide.

Related

Passing Stripe Fee to Customer: Unaccounted Profit with Formula Usage

Referring to when you pass the Stripe fee to your customer by offsetting the final total charge to them using the given formula.
Considering the following scenario for a Payment Intent:
Buyer is purchasing a $1,000.00 item (Pgoal)
Buyer is charged Australian Stripe fees of 1.75% on the item (Fpercent)
Buyer is charged a fixed fee of $0.30 AUD (Ffixed)
Buyer is charged a 10% tax only on the Stripe fees component (Ftax, i.e. 10% of whatever is 1.75% of the amount + 30c fixed)
When I check Stripe Dashboard for this Payment Intent using the formula prescribed by Stripe, the following is calculated:
Amount: A$1,019.92
Fee: A$18.15
Stripe Processing Fees: A$16.50
Tax: A$1.65
Net: A$1,001.77
The problem is why am I profiting $1.77?? It should be $1,000.00 flat. Not sure what I'm doing wrong, so any help is appreciated.
The formula Stripe provides is pretty straight forward:
Pcharge = ( Pgoal + Ffixed )
------------------
( 1 - Fpercent )
- Pgoal is $1,000.00 or 100000 (in cents)
- Ffixed is 0.30 or 30 (in cents)
- Fpercent is 1.75% or 0.0175
The only issue with above formula is that it doesn't account for Stripe's taxes it charges the Buyer, which in Australia is 10% on the total Stripe fees. So I've gone ahead and accounted for it in the numerator of the formula:
Pcharge = ( Pgoal + Ffixed + Ftax )
-------------------------
( 1 - Fpercent )
- Pgoal is $1,000.00 or 100000 (in cents)
- Ffixed is 0.30 or 30 (in cents)
- Fpercent is 1.75% or 0.0175
- Ftax is 10% on the Stripe fees, or [ 0.1 * ( Pgoal * Fpercent + Ffixed ) ]

Ruby script to calculate discount using Shopify Scripts

I am using a script to calculate an addtional 5% off when the cart total is greater than $1000, but the variant price is already discounted by 25% and has a was/now pricing setup that is $29.95 was $39.95.
The problem is - i need for the script to discount the orginal item value of $39.95, not the discounted rate which is the new retail price.
Here is the script - i have tried to add 25% back to the line item price without success and there is no line item method that Shopify provides to use the orginal cart line item price in the dev docs - https://help.shopify.com/en/manual/checkout-settings/script-editor/shopify-scripts#line-item-methods
# Tiered Discounts by Spend Threshold 5% off when you spend $1000 or more
min_discount_order_amount_extra = Money.new(cents:100) * 1000 #number of dollars needed in cart to get the discount
DISCOUNT_PERCENT = 25
# calculate the discount to be applied
percent = Decimal.new(DISCOUNT_PERCENT/100) + 1
total = Input.cart.subtotal_price_was * percent
discount = if total > min_discount_order_amount_extra
0.05 #discount percentage in decimal form
else
0
end
message = "Another 5% saved"
# 30% off products excluding commercial items
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next if line_item.variant.product.tags.any?{|x| ['commercial'].include?(x)};
line_item.change_line_price(line_item.line_price * (1-discount), message: message) unless discount == 0
end
Output.cart = Input.cart

Generation of PDF from Google Form using Doc template using Script

I am using this script to create PDF from Google from using template in Google Docs.
The script I am using is as below:
function afterFormSubmit(e) {
const info = e.namedValues;
const pdfFile = createPDF(info);
const entryRow = e.range.getRow();
const ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2")
ws.getRange(entryRow, 63).setValue(pdfFile.getUrl());
ws.getRange(entryRow, 64).setValue(pdfFile.getName());
sendEmail(e.namedValues ['Email address'][0],pdfFile);
}
function sendEmail(email,pdfFile){
GmailApp.sendEmail(email, "Daily Transation Summary Report", "Please find the attached DTR", {
attachments : [pdfFile],
name: 'My Company'
});
}
function createPDF(info) {
const pdfFolder = DriveApp.getFolderById("1ebglel6vwMGXByeG4wHBBvJu9u0zJeMJ");
const tempFolder = DriveApp.getFolderById("1ebglel6vwMGXByeG4wHBBvJu9u0zJeMJ");
const templateDoc = DriveApp.getFileById("1kyFimRMdHQZV85F5P6JyCHv1DQ3KJFv1hx5o7lIcNZo");
const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
body.replaceText("{Name of Person}", info['Name of Person'][0]);
body.replaceText("{Date of Report}", info['Date of Report'][0]);
body.replaceText("{Name of Outlet}", info['Name of Outlet'][0]);
body.replaceText("{Opening Petty Cash Balance}", info['Opening Petty Cash Balance'][0]);
body.replaceText("{Total Petty Cash Received}", info['Total Petty Cash Received'][0]);
body.replaceText("{Closing Petty Cash Balance}", info['Closing Petty Cash Balance'][0]);
body.replaceText("{Total Petty Cash Paid}", info['Total Petty Cash Paid'][0]);
body.replaceText("{Available Float Cash Balance}", info['Available Float Cash Balance'][0]);
body.replaceText("{Milk For Outlet}", info['Milk For Outlet'][0]);
body.replaceText("{Staff Milk/Toast etc.}", info['Staff Milk/Toast etc.'][0]);
body.replaceText("{Petrol Expenses}", info['Petrol Expenses'][0]);
body.replaceText("{Water Tank Charges}", info['Water Tank Charges'][0]);
body.replaceText("{Repair And Maintenance}", info['Repair And Maintenance'][0]);
body.replaceText("{Freight Paid}", info['Freight Paid'][0]);
body.replaceText("{Purchase of Soya Chaap}", info['Purchase of Soya Chaap'][0]);
body.replaceText("{Purchase of Rumali Roti}", info['Purchase of Rumali Roti'][0]);
body.replaceText("{Purchase of Egg Tray}", info['Purchase of Egg Tray'][0]);
body.replaceText("{Other Expenses}", info['Other Expenses'][0]);
body.replaceText("{Total Tip Amount (PAYTM & CARD)}", info['Total Tip Amount (PAYTM & CARD)'][0]);
body.replaceText("{Cash Sales - Outlet}", info['Cash Sales - Outlet'][0]);
body.replaceText("{Cash Sales - KCCO App}", info['Cash Sales - KCCO App'][0]);
body.replaceText("{Card Sales}", info['Card Sales'][0]);
body.replaceText("{Credit (Udhar) Sales}", info['Credit (Udhar) Sales'][0]);
body.replaceText("{Paytm Sales}", info['Paytm Sales'][0]);
body.replaceText("{KCCO App Sales Razor Pay}", info['KCCO App Sales Razor Pay'][0]);
body.replaceText("{Swiggy Sales}", info['Swiggy Sales'][0]);
body.replaceText("{Zomato Sales}", info['Zomato Sales'][0]);
body.replaceText("{Dunzo Sales}", info['Dunzo Sales'][0]);
body.replaceText("{Zomato Gold Sales}", info['Zomato Gold Sales'][0]);
body.replaceText("{Dine Out Sales}", info['Dine Out Sales'][0]);
body.replaceText("{Total Cancelled Bill Amount}", info['Total Cancelled Bill Amount'][0]);
body.replaceText("{Total Sales of the Day (Total of Above)}", info['Total Sales of the Day (Total of Above)'][0]);
body.replaceText("{Total Sales of the Day (As Per PetPooja)}", info['Total Sales of the Day (As Per PetPooja)'][0]);
body.replaceText("{Old Due Receipts - Cash}", info['Old Due Receipts - Cash'][0]);
body.replaceText("{Old Due Receipts - Other Modes}", info['Old Due Receipts - Other Modes'][0]);
body.replaceText("{Tip Receipts - Card}", info['Tip Receipts - Card'][0]);
body.replaceText("{Tip Receipts - Paytm}", info['Tip Receipts - Paytm'][0]);
body.replaceText("{Currency Note of INR 2000}", info['Currency Note of INR 2000'][0]);
body.replaceText("{Currency Note of INR 500}", info['Currency Note of INR 500'][0]);
body.replaceText("{ Currency Note of INR 200}", info[' Currency Note of INR 200'][0]);
body.replaceText("{Currency Note of INR 100}", info['Currency Note of INR 100'][0]);
body.replaceText("{Currency Note of INR 50}", info['Currency Note of INR 50'][0]);
body.replaceText("{Currency Note of INR 20}", info['Currency Note of INR 20'][0]);
body.replaceText("{Currency Note of INR 10}", info['Currency Note of INR 10'][0]);
body.replaceText("{Other Currency Note/Coins}", info['Other Currency Note/Coins'][0]);
body.replaceText("{Total Available Cash to Handover}", info['Total Available Cash to Handover'][0]);
body.replaceText("{S.No.//Name of Person// Mobile No// Credit Approval By// Bill No// Total Amount of Credit", info['S.No.//Name of Person// Mobile No// Credit Approval By// Bill No// Total Amount of Credit'][0]);
body.replaceText("{Total No. of Bills of Credit Recovery}", info['Total No. of Bills of Credit Recovery'][0]);
body.replaceText("{S.No.//Name of Person// Mobile No// Mode of Payment// Bill No// Total Amount Received}", info['S.No.//Name of Person// Mobile No// Mode of Payment// Bill No// Total Amount Received'][0]);
body.replaceText("{Total No. of Complementary Bills During the Day}", info['Total No. of Complementary Bills During the Day'][0]);
body.replaceText("{S.No.//Name of Person// Mobile No//Reason// Bill No//Amount Settled}", info['S.No.//Name of Person// Mobile No//Reason// Bill No//Amount Settled'][0]);
body.replaceText("{Total No. of Cancelled Bills During the Day}", info['Total No. of Cancelled Bills During the Day'][0]);
body.replaceText("{S.No.//Name of Person// Mobile No// Bill No// Bill Amount}", info['S.No.//Name of Person// Mobile No// Bill No// Bill Amount'][0]);
body.replaceText("{S.No.// Bill No// Mode of Payment//Tip Amount Received}", info['S.No.// Bill No// Mode of Payment//Tip Amount Received'][0]);
body.replaceText("{No. of Cylinders Received at Outlet}", info['No. of Cylinders Received at Outlet'][0]);
openDoc.saveAndClose();
const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Name of Outlet'][0]+ " " + info['Date of Report'][0]);
tempFolder.removeFile(newTempFile);
return pdfFile;
}
This script is not generating PDF as well PDF is not being Mailed.
The link of Spreadsheet is as below
https://docs.google.com/spreadsheets/d/1m6Aca0TcLf5UZ7P9CvAdQDokoazQljsqDT6CGh0K3j4/edit?usp=sharing
Please guide.

I cannot parse multi-row json array and put it into the html elements

var dataJSON = '[{"FeeType":"Domestic POS Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"Domestic PIN Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"International POS Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"International PIN Declined Fee ","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"ATM Domestic Fee <sup>1</sup>","FeeDescription":"One (1) no cost ATM withdrawal per deposit1, then $1.75 per transaction thereafter","FeeAmount":"1.75"},{"FeeType":"Domestic ATM Balance Inquiry Fee <sup>1</sup>","FeeDescription":"per ATM Balance Inquiry","FeeAmount":"0.50"},{"FeeType":"Domestic ATM Declined Fee <sup>1</sup>","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"International ATM Withdrawal Fee <sup>1</sup>","FeeDescription":"per transaction","FeeAmount":"3.00"},{"FeeType":"International ATM Balance Fee ","FeeDescription":"per ATM Balance Inquiry","FeeAmount":"0.95"},{"FeeType":"International ATM Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"OTC Withdrawal Fee","FeeDescription":"per transaction","FeeAmount":"4.00"},{"FeeType":"International OTC Withdrawal Fee","FeeDescription":"per transaction","FeeAmount":"4.00"},{"FeeType":"Currency Conversion Fee","FeeDescription":"3% of transaction amount","FeeAmount":"3.00%"},{"FeeType":"Card Replacement Fee","FeeDescription":"One (1) no cost replacement per calendar year or upon expiration; $5.00 per request thereafter for lost, stolen, and damaged cards.","FeeAmount":"5.00"},{"FeeType":" Expedited Card Replacement Fee ","FeeDescription":"$20.00 (per Card; an additional fee when a Card is reissued or replaced for any reason with requested expedited delivery)","FeeAmount":"20.00"},{"FeeType":"Check Refund Fee","FeeDescription":"$12.50 per refund check (When a refund check is issued for the remaining Card balance.","FeeAmount":"12.5"}]';
var dataObject = JSON.parse(dataJSON);
var listItemString = $('#listItem').html();
dataObject.forEach(buildNewList);
function buildNewList(item, index) {
var listItem = $('<li class="collection-item">' + listItemString + '</li>');
var listItemTitle = $('.title', listItem);
listItemTitle.html(item.FeeType);
var listItemDesc = $('.description', listItem);
listItemDesc.html(item.FeeDescription);
$('#myUL').append(listItem);
}
var myObj2 = {
"kelimeler": [
{
"title": "",
"description": "T�rkiyenin en b�y�k do_rudan sat�_ _irketi"
},
{
"title": "Aktif Temsilci",
"description": "Bir kampanyada sipari_ veren ve �d�l sat�_ tutar� s�f�rdan b�y�k olan temsilci"
},
] }
I found some code on the internet.
var dataObject = JSON.parse(dataJSON);
this works perfectly but it is really hard for me to manage a single line json array. I just want to use myObj2 and access the title and desciption.
How can I access the elements inside myObj2 > 'keliemeler' . I tried item.kelimeler.title something but it didn't work.
Thanks.
item.kelimeler will never shown since it's only in myObj2, and item is taken from dataJSON that doesn't have kelimeler.

How to parse JSON and put in HTML with infinite scroll?

I want to read data from a json file and put in html. The json contains lots of data, so I want to use infinite scroll with it.
I have searched and found this example: https://codepen.io/anantanandgupta/pen/oLLgyN
var dataJSON = '[{"FeeType":"Domestic POS Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"Domestic PIN Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"International POS Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"International PIN Declined Fee ","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"ATM Domestic Fee <sup>1</sup>","FeeDescription":"One (1) no cost ATM withdrawal per deposit1, then $1.75 per transaction thereafter","FeeAmount":"1.75"},{"FeeType":"Domestic ATM Balance Inquiry Fee <sup>1</sup>","FeeDescription":"per ATM Balance Inquiry","FeeAmount":"0.50"},{"FeeType":"Domestic ATM Declined Fee <sup>1</sup>","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"International ATM Withdrawal Fee <sup>1</sup>","FeeDescription":"per transaction","FeeAmount":"3.00"},{"FeeType":"International ATM Balance Fee ","FeeDescription":"per ATM Balance Inquiry","FeeAmount":"0.95"},{"FeeType":"International ATM Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"OTC Withdrawal Fee","FeeDescription":"per transaction","FeeAmount":"4.00"},{"FeeType":"International OTC Withdrawal Fee","FeeDescription":"per transaction","FeeAmount":"4.00"},{"FeeType":"Currency Conversion Fee","FeeDescription":"3% of transaction amount","FeeAmount":"3.00%"},{"FeeType":"Card Replacement Fee","FeeDescription":"One (1) no cost replacement per calendar year or upon expiration; $5.00 per request thereafter for lost, stolen, and damaged cards.","FeeAmount":"5.00"},{"FeeType":" Expedited Card Replacement Fee ","FeeDescription":"$20.00 (per Card; an additional fee when a Card is reissued or replaced for any reason with requested expedited delivery)","FeeAmount":"20.00"},{"FeeType":"Check Refund Fee","FeeDescription":"$12.50 per refund check (When a refund check is issued for the remaining Card balance.","FeeAmount":"12.5"}]';
var dataObject = JSON.parse(dataJSON);
var listItemString = $('#listItem').html();
dataObject.forEach(buildNewList);
function buildNewList(item, index) {
var listItem = $('<li>' + listItemString + '</li>');
var listItemTitle = $('.title', listItem);
listItemTitle.html(item.FeeType);
var listItemAmount = $('.amount', listItem);
listItemAmount.html(item.FeeAmount);
var listItemDesc = $('.description', listItem);
listItemDesc.html(item.FeeDescription);
$('#dataList').append(listItem);
}
This is what I want for parse the json. But it does not include infinite scroll. So how to make it infinite scroll?
You should add an event listener to the div in which you want to append the content (in your case $('#dataList') ), so that every time there is a scroll in the scrolled div the script checks if the bottom was reached.
// Detect when scrolled bottom
$('#dataList').addEventListener('scroll', function() {
if ($('#dataList').scrollTop + $('#dataList').clientHeight >= $('#dataList').scrollHeight) {
loadMore();
}
});
//Loading more elements
function loadMore(){
var dataJSON = '[{"FeeType":"Domestic POS Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"Domestic PIN Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"International POS Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"International PIN Declined Fee ","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"ATM Domestic Fee <sup>1</sup>","FeeDescription":"One (1) no cost ATM withdrawal per deposit1, then $1.75 per transaction thereafter","FeeAmount":"1.75"},{"FeeType":"Domestic ATM Balance Inquiry Fee <sup>1</sup>","FeeDescription":"per ATM Balance Inquiry","FeeAmount":"0.50"},{"FeeType":"Domestic ATM Declined Fee <sup>1</sup>","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"International ATM Withdrawal Fee <sup>1</sup>","FeeDescription":"per transaction","FeeAmount":"3.00"},{"FeeType":"International ATM Balance Fee ","FeeDescription":"per ATM Balance Inquiry","FeeAmount":"0.95"},{"FeeType":"International ATM Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"OTC Withdrawal Fee","FeeDescription":"per transaction","FeeAmount":"4.00"},{"FeeType":"International OTC Withdrawal Fee","FeeDescription":"per transaction","FeeAmount":"4.00"},{"FeeType":"Currency Conversion Fee","FeeDescription":"3% of transaction amount","FeeAmount":"3.00%"},{"FeeType":"Card Replacement Fee","FeeDescription":"One (1) no cost replacement per calendar year or upon expiration; $5.00 per request thereafter for lost, stolen, and damaged cards.","FeeAmount":"5.00"},{"FeeType":" Expedited Card Replacement Fee ","FeeDescription":"$20.00 (per Card; an additional fee when a Card is reissued or replaced for any reason with requested expedited delivery)","FeeAmount":"20.00"},{"FeeType":"Check Refund Fee","FeeDescription":"$12.50 per refund check (When a refund check is issued for the remaining Card balance.","FeeAmount":"12.5"}]';
var dataObject = JSON.parse(dataJSON);
var listItemString = $('#listItem').html();
dataObject.forEach(buildNewList);
}
//Building an element
function buildNewList(item, index) {
var listItem = $('<li>' + listItemString + '</li>');
var listItemTitle = $('.title', listItem);
listItemTitle.html(item.FeeType);
var listItemAmount = $('.amount', listItem);
listItemAmount.html(item.FeeAmount);
var listItemDesc = $('.description', listItem);
listItemDesc.html(item.FeeDescription);
$('#dataList').append(listItem);
}

Categories