NodeJs Javascript Calling a Function Dynamically From an Array

Custard

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.

Custard

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Javascript

Calling a Javascript Function from Console

From Javascript

Calling JavaScript Function From CodeBehind

From Dev

Returning Array and assign to array from calling function

From Dev

Using javascript objects as a "function store" and calling them dynamically?

From Dev

Calling C function from returned pointer in NodeJS

From Dev

Calling functions as dynamic function as array values in javascript

From Dev

Angelscript calling overriding function from object in array

From Dev

Javascript function calling inside an array of objects?

From Dev

JavaScript: Not calling javascript function from the code behind

From Dev

Calling a Javascript function from .cs

From Dev

Function Calling Execution in nodejs

From Dev

Javascript calling function from inside same function

From Dev

Calling string from array using loop after onclick function [javascript]

From Dev

Calling multiple arguments in an array from a function [PHP]

From Dev

javascript calling function as array element

From Dev

Calling the Javascript Function once the table is loaded dynamically using ajax call

From Dev

Calling JavaScript function from [WebMethod]

From Dev

Calling a JavaScript function inside PHP Array

From Dev

Calling nodeJS from angularJS function

From Dev

Calling function, from callback stored in object, in an array

From Dev

how to load sub category based on category by calling jquery function from <td> of javascript function for adding rows dynamically?

From Dev

Calling a derived function from an array of the base class

From Dev

Calling a function with a dynamically allocated array pointer

From Dev

Returning an array from function in nodejs

From Dev

calling websocket send function from within .then() in nodejs

From Dev

Calling function with callback in nodejs

From Dev

How to set up a function dynamically without calling it in javascript?

From Dev

Calling Laravel function dynamically

From Dev

Calling nodeJS HTTP server from Javascript

Related Related

  1. 1

    Calling a Javascript Function from Console

  2. 2

    Calling JavaScript Function From CodeBehind

  3. 3

    Returning Array and assign to array from calling function

  4. 4

    Using javascript objects as a "function store" and calling them dynamically?

  5. 5

    Calling C function from returned pointer in NodeJS

  6. 6

    Calling functions as dynamic function as array values in javascript

  7. 7

    Angelscript calling overriding function from object in array

  8. 8

    Javascript function calling inside an array of objects?

  9. 9

    JavaScript: Not calling javascript function from the code behind

  10. 10

    Calling a Javascript function from .cs

  11. 11

    Function Calling Execution in nodejs

  12. 12

    Javascript calling function from inside same function

  13. 13

    Calling string from array using loop after onclick function [javascript]

  14. 14

    Calling multiple arguments in an array from a function [PHP]

  15. 15

    javascript calling function as array element

  16. 16

    Calling the Javascript Function once the table is loaded dynamically using ajax call

  17. 17

    Calling JavaScript function from [WebMethod]

  18. 18

    Calling a JavaScript function inside PHP Array

  19. 19

    Calling nodeJS from angularJS function

  20. 20

    Calling function, from callback stored in object, in an array

  21. 21

    how to load sub category based on category by calling jquery function from <td> of javascript function for adding rows dynamically?

  22. 22

    Calling a derived function from an array of the base class

  23. 23

    Calling a function with a dynamically allocated array pointer

  24. 24

    Returning an array from function in nodejs

  25. 25

    calling websocket send function from within .then() in nodejs

  26. 26

    Calling function with callback in nodejs

  27. 27

    How to set up a function dynamically without calling it in javascript?

  28. 28

    Calling Laravel function dynamically

  29. 29

    Calling nodeJS HTTP server from Javascript

HotTag

Archive