So I've searched around stack overflow and cant seem to find anything that people have suggested that works.
So I have an Object Array
Report_Search_List = [
{"NAME":"CHART OF ACCOUNTS", "PDF":"CHART_OF_ACCOUNTS_PDF", "XLS":"CHART_OF_ACCOUNTS_XLS"},
{"NAME":"GENERAL LEDGER", "PDF":"GENERAL_LEDGER_PDF", "XLS":"GENERAL_LEDGER_XLS"},
{"NAME":"COST REPORT", "PDF":"COST_REPORT_PDF", "XLS":"COST_REPORT_XLS"},
{"NAME":"CASH FLOW", "PDF":"CASH_FLOW_PDF", "XLS":"CASH_FLOW_XLS"},
{"NAME":"INVOICE", "PDF":"INVOICE_PDF", "XLS":"INVOICE_XLS"},
{"NAME":"CREDIT NOTE", "PDF":"CREDIT_NOTE_PDF", "XLS":"CREDIT_NOTE_XLS"},
{"NAME":"JOBCARD COST", "PDF":"JOBCARD_COST_PDF", "XLS":"JOBCARD_COST_XLS"},
{"NAME":"GOODS RECEIVED VOUCHER", "PDF":"GOODS_RECEIVED_VOUCHER_PDF", "XLS":"GOODS RECEIVED VOUCHER_XLS"},
{"NAME":"GOODS RETURNED NOTE", "PDF":"GOODS_RETURNED_NOTE_PDF", "XLS":"GOODS_RETURNED_NOTE_XLS"},
{"NAME":"REQUISITION", "PDF":"REQUISITION_PDF", "XLS":"REQUISITION_XLS"},
{"NAME":"DELIVERY NOTE", "PDF":"DELIVERY_NOTE_PDF", "XLS":"DELIVERY_NOTE_XLS"},
{"NAME":"PICK SLIP", "PDF":"PICK_SLIP_PDF", "XLS":"PICK_SLIP_XLS"},
{"NAME":"PETTY CASH", "PDF":"PETTY_CASH_PDF", "XLS":"DELIVERY_NOTE_XLS"},
{"NAME":"OTHER TRANSACTIONS", "PDF":"OTHER_TRANSACTIONS_PDF", "XLS":"OTHER_TRANSACTIONS_XLS"},
{"NAME":"PURCHASE ORDER", "PDF":"PURCHASE_ORDER_PDF", "XLS":"PURCHASE_ORDER_XLS"}
]
So it first builds a Search list for the user to select from
Report_Search_List[index].NAME
Then once they have selected the report they click on the button either PDF or XLS
here is the function
function PDF_CLICK() {
try {
var text = "none";
var BRANCH_PDF_REPORTS_PROFILE_SELECT = document.getElementById('BRANCH_PDF_REPORTS_PROFILE_SELECT');
text = BRANCH_PDF_REPORTS_PROFILE_SELECT.value;
//get array list
var report = Report_Search_List.filter(function (el) {
return el["NAME"] == text;
});
//PROBLEM IS HERE
//run method
Window[report[0]["PDF"]]();
window[report[0]["PDF"]]();
report[0]["PDF"].call();
report[0]["PDF"]();
} catch (e) {
console.log(e);
EX_JS_ALERT.ALERT("OOPS SOMETHING WENT WRONG"); EX_JS_ERROR.ERROR(e.toString(), location.pathname);;
}
}
Now the problem
I've tried all of the above and it is getting the correct report but still comes back with its not a function. Meanwhile there is a function below.
So I figured out how to do it window is not the current window you are working on.
so what i did at the top of the page is
const EX_JS_BRANCH_REPORTS_PDF = require('../BRANCH/EX_JS_BRANCH_REPORTS_PDF.js');
then changed the
function to
exports.GENERAL_LEDGER_PDF = function(){}
then I changed window to EX_JS_BRANCH_REPORTS_PDF and dynamically working XD
EX_JS_BRANCH_REPORTS_PDF[report[0]["PDF"]]();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments