Issues with formatting of data as input to pdf make

Continuing the discussion from MySQL Database Output (>500 rows) to be added to pdfmake:

Dear Sir,
I am somehow stuck with one issue similar to above link where E1cid had helped me. I am trying to build a pdf report using some images and data from mysql. my flow is given as below and the output from mysql node is also pasted below. Mysql output is ok. I am getting error at function node name "table format".

[
    {
        "id": "553ad1fd299a4566",
        "type": "function",
        "z": "b1685cf1.3f411",
        "name": "Table format",
        "func": "//datetime\n//var time = new Date().toLocaleString(\"de\");\nvar time1 = flow.get('current_date_time')\n\nlet payload = {\n\tpageOrientation: 'landscape',\n\tcontent: [\n\t\t{\n\t\t\tcolumnGap: 20,\n\t\t\tcolumns: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\timage: msg.genuslogo,\n\t\t\t\t\t\t\tfit: [75, 75],\n\t\t\t\t\t\t\talignment: 'left'\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttext: 'OVENS STATUS REPORT',\n\t\t\t\t\t\t\tstyle: 'header',\n\t\t\t\t\t\t\talignment: 'center',\n\t\t\t\t\t\t\twidth: 300,\n\t\t\t\t\t\t\tmargin: [0, 0, 20, 0]\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\timage: msg.stlogo,\n\t\t\t\t\t\t\tfit: [50, 50],\n\t\t\t\t\t\t\talignment: 'right'\n\t\t\t\t\t\t},\n\n\n\t\t\t\t\t]\n\t\t\t\t},\n\n\t\t{\n\t\t\ttext: 'REPORT DATE_TIME: ' + time1 + '',\n\t\t\tstyle: 'header'\n\t\t},\n\n\n\t\t'\\n\\n',\n\t\t'Status for all Ovens is given in below table:',\n\t\t'\\n\\n',\n\t\t\n\t\t{\n\t\t\tstyle: 'datatable',\n\t\t\talignment: 'center',\n\t\t\ttable: {\n\t\t\t\theaderRows: 1,\n\t\t\t\tfontSize: 7,\n\t\t\t\tbody: [\n\t\t\t\t\t[{ text: 'Line', style: 'tableHeader' }, { text: 'Oven Name', style: 'tableHeader' }, { text: 'Batch Name', style: 'tableHeader' }, { text: 'Sub Batch Name', style: 'tableHeader' }, { text: 'Plate Type', style: 'tableHeader' }, { text: 'Plate Spec', style: 'tableHeader' }, { text: 'Plate Qty', style: 'tableHeader' }, { text: 'Start Time', style: 'tableHeader' }, { text: 'Sch End Time', style: 'tableHeader'}, { text: 'Balance Process Time', style: 'tableHeader' }],\n\t\t\t\t]\n\t\t\t}\n\t\t},\n\t],\n\t\t\n\tstyles: {\n\t\theader: {\n\t\t\tfontSize: 18,\n\t\t\tbold: true,\n\t\t\tmargin: [0, 0, 0, 10]\n\n\t\t},\n\t\tsubheader: {\n\t\t\tfontSize: 16,\n\t\t\tbold: true,\n\t\t\tmargin: [0, 10, 0, 5]\n\t\t},\n\t\ttableExample: {\n\t\t\tmargin: [0, 5, 0, 15],\n\t\t\talignment: 'right'\n\t\t},\n\t\ttableHeader: {\n\t\t\tbold: true,\n\t\t\tfontSize: 10,\n\t\t\tcolor: 'black'\n\t\t},\n\t\tdatatable: {\n\t\t\tbold: false,\n\t\t\tfontSize: 10,\n\t\t\tcolor: 'black'\n\t\t},\n\t\tquote: {\n\t\t\titalics: true\n\t\t}\n\t}\n};\nmsg.payload.forEach((obj, index) => {\n\n\tlet output = [`Line${index + 1}`];\n\tObject.values(obj).forEach(val => output.push(val));\n\tpayload.content[4].table.body.push(output)\n})\nmsg.payload = payload;\nmsg.filename = 'D:\\Genus\\Reports\\Daily_report17122022.pdf'\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 990,
        "y": 280,
        "wires": [
            [
                "9c4396b74064f12f"
            ]
        ]
    },
    {
        "id": "27b307e71719c9d0",
        "type": "file",
        "z": "b1685cf1.3f411",
        "name": "write file",
        "filename": "filename",
        "filenameType": "msg",
        "appendNewline": false,
        "createDir": true,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 1300,
        "y": 280,
        "wires": [
            [
                "3f5c0a06a9fd4ef8"
            ]
        ]
    },
    {
        "id": "9c4396b74064f12f",
        "type": "pdfmake",
        "z": "b1685cf1.3f411",
        "name": "",
        "outputType": "Buffer",
        "inputProperty": "payload",
        "options": "{}",
        "outputProperty": "payload",
        "x": 1160,
        "y": 280,
        "wires": [
            [
                "27b307e71719c9d0"
            ]
        ]
    },
    {
        "id": "116d7e0a8d17f679",
        "type": "inject",
        "z": "b1685cf1.3f411",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 260,
        "y": 280,
        "wires": [
            [
                "1888a61d093e566b"
            ]
        ]
    },
    {
        "id": "3f5c0a06a9fd4ef8",
        "type": "debug",
        "z": "b1685cf1.3f411",
        "name": "debug 25",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1460,
        "y": 280,
        "wires": []
    },
    {
        "id": "1888a61d093e566b",
        "type": "jimp-image",
        "z": "b1685cf1.3f411",
        "name": "",
        "data": "D:\\Genus\\Data\\Images\\genus_logo.png",
        "dataType": "str",
        "ret": "b64",
        "parameter1": "",
        "parameter1Type": "msg",
        "parameter2": "",
        "parameter2Type": "msg",
        "parameter3": "",
        "parameter3Type": "msg",
        "parameter4": "",
        "parameter4Type": "msg",
        "parameter5": "",
        "parameter5Type": "msg",
        "parameter6": "",
        "parameter6Type": "msg",
        "parameter7": "",
        "parameter7Type": "msg",
        "parameter8": "",
        "parameter8Type": "msg",
        "sendProperty": "genuslogo",
        "sendPropertyType": "msg",
        "parameterCount": 0,
        "jimpFunction": "none",
        "selectedJimpFunction": {
            "name": "none",
            "fn": "none",
            "description": "Just loads the image.",
            "parameters": []
        },
        "x": 410,
        "y": 280,
        "wires": [
            [
                "2dc4e742f1e02f46"
            ]
        ]
    },
    {
        "id": "2dc4e742f1e02f46",
        "type": "jimp-image",
        "z": "b1685cf1.3f411",
        "name": "",
        "data": "D:\\Genus\\Data\\Images\\saraltech_logo.png",
        "dataType": "str",
        "ret": "b64",
        "parameter1": "",
        "parameter1Type": "msg",
        "parameter2": "",
        "parameter2Type": "msg",
        "parameter3": "",
        "parameter3Type": "msg",
        "parameter4": "",
        "parameter4Type": "msg",
        "parameter5": "",
        "parameter5Type": "msg",
        "parameter6": "",
        "parameter6Type": "msg",
        "parameter7": "",
        "parameter7Type": "msg",
        "parameter8": "",
        "parameter8Type": "msg",
        "sendProperty": "stlogo",
        "sendPropertyType": "msg",
        "parameterCount": 0,
        "jimpFunction": "none",
        "selectedJimpFunction": {
            "name": "none",
            "fn": "none",
            "description": "Just loads the image.",
            "parameters": []
        },
        "x": 570,
        "y": 280,
        "wires": [
            [
                "f3809d495b42387b"
            ]
        ]
    },
    {
        "id": "f3809d495b42387b",
        "type": "function",
        "z": "b1685cf1.3f411",
        "name": "Select",
        "func": "msg.topic = \"select oven_name, batch_name, sub_batch, plate_type, plate_spec, plate_qty, CONVERT_TZ(start_time, '+00:00' , '+05:30'), CONVERT_TZ(sch_end_time, '+00:00' , '+05:30'), TIMESTAMPDIFF(HOUR, NOW(), sch_end_time) as TD from batch_data where current_status = 'In Progress' order by oven_id\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 690,
        "y": 280,
        "wires": [
            [
                "ae6188a79ecd0fec"
            ]
        ]
    },
    {
        "id": "ae6188a79ecd0fec",
        "type": "mysql",
        "z": "b1685cf1.3f411",
        "mydb": "09be9f5fb6a976de",
        "name": "",
        "x": 840,
        "y": 280,
        "wires": [
            [
                "553ad1fd299a4566"
            ]
        ]
    },
    {
        "id": "09be9f5fb6a976de",
        "type": "MySQLdatabase",
        "name": "",
        "host": "127.0.0.1",
        "port": "3306",
        "db": "gil_oven",
        "tz": "",
        "charset": "UTF8"
    }
]


image

Please help me to understand what is wrong with the code in function node "Table format". Thanks a lot for your support.

payload.content[4].table.body.push(output)

should be

payload.content[5].table.body.push(output)

Don't know about anything else as I do not use MySQL

		'\n\n',
		'Status for all Ovens is given in below table:',
		'\n\n',

Counts as three elements in the Array

1 Like

Thanks a lot Sir. It worked perfectly well. I missed this fine point. I appreciate your support.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.