Hi All,
I am attaching the flow below ,where here using 2 moment nodes(node-red-contrib-moment) in the same flow, and I am facing the issue second moment node and insert function is printing twice in the debug console , so because of this, same two records are inserting into the database.
can you please help me .
here is the flow::
[{"id":"3e35e26b.9511be","type":"tab","label":"Order Sync to ERP","disabled":false,"info":""},{"id":"35df9403.12eb4c","type":"function","z":"3e35e26b.9511be","name":"Payload is not empty","func":" var SCBASICSYNC = global.get('appconfig').oracledbschema + .
+ global.get('appconfig').tableSCBASICSYNC;\n \n var orderbpmid = msg.payload.ORDERBPMID;\n node.log("orderbpmID=====>", +orderbpmid);\n \n var query = select * from
+ SCBASICSYNC + where ORDERBPMID = '
+ orderbpmid + '
\n msg.payload.query = query;\n \n return msg;","outputs":1,"noerr":0,"x":840,"y":120,"wires":[["63b73e4.56618c","b441396c.c303f8"]]},{"id":"3c89b607.f3e00a","type":"http in","z":"3e35e26b.9511be","name":"","url":"/vaighaibpm/api/v1/order","method":"post","upload":false,"swaggerDoc":"","x":190,"y":320,"wires":[["4422e947.e86728","f3d4af81.ebd4b","441e929.333d26c"]]},{"id":"db3d69a4.fb6098","type":"inject","z":"3e35e26b.9511be","name":"","topic":"","payload":"{"ORDERNUMBER":"ord-64","ORDERBPMID":"65cd-45f16-4f71-9ass-7b48a4ec0125","PARTYMASTID":"123456","PARTYMASTBMPID":"b2b04473-5f16-4f71-9a63-7b48a4ec01b2","ITEMMASTERID":"5500","ITEMMASTERBPMID":"k04473-5f16-4f71-9a63-7b48a4ec0166","UNIT":"hours","QTY":"1","ABCGRADE":"","RATE":"200","AMOUNT":"200","REMARKS":"","DUEDATE":"2019-02-26T16:55:00","ASTATUS":"Pending","USERCTRL":"abc","SALETYPE":"","SECTOR":"Fuel","SCBASICID":7656,"CONTRACTDOCID":"","CONTRACTBPMID":"","ORDSYNCSTATUS":"pending","ITEMID":"70042000119723","ITEMDESC":"Tablet is 7.00-inch display,resolution 1024 pixels by 600 pixels","PRIUNIT":"0909"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":240,"wires":[["4422e947.e86728","441e929.333d26c","50af73f8.8a1f9c"]]},{"id":"4422e947.e86728","type":"switch","z":"3e35e26b.9511be","name":"Checking SCBasicSync has same record","property":"payload","propertyType":"msg","rules":[{"t":"nempty"},{"t":"empty"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":160,"wires":[["35df9403.12eb4c"],["11a3871e.66ed39"]]},{"id":"11a3871e.66ed39","type":"function","z":"3e35e26b.9511be","name":"Payload is empty","func":"var SCBASICSYNC = global.get('appconfig').oracledbschema + .
+ global.get('appconfig').tableSCBASICSYNC;\nreturn null;","outputs":1,"noerr":0,"x":830,"y":200,"wires":[["638eb135.25a12"]]},{"id":"50b5d381.bb7cbc","type":"http response","z":"3e35e26b.9511be","name":"Failure response","statusCode":"400","headers":{},"x":550,"y":320,"wires":},{"id":"638eb135.25a12","type":"function","z":"3e35e26b.9511be","name":"Failure message","func":"msg.payload = {};\n\nmsg.payload.status="failed";\n\nmsg.payload.message = "Failed to Post data check input data"\n\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":260,"wires":[["50b5d381.bb7cbc"]]},{"id":"f3d4af81.ebd4b","type":"debug","z":"3e35e26b.9511be","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":290,"y":400,"wires":},{"id":"441e929.333d26c","type":"link out","z":"3e35e26b.9511be","name":"","links":["e0a9e450.95daa8"],"x":335,"y":100,"wires":},{"id":"63b73e4.56618c","type":"debug","z":"3e35e26b.9511be","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":950,"y":60,"wires":},{"id":"b441396c.c303f8","type":"oracle-db","z":"3e35e26b.9511be","name":"","x":1090,"y":220,"wires":[["1dff65.cfbbf09b","e1c26a14.db41a8"]]},{"id":"1dff65.cfbbf09b","type":"debug","z":"3e35e26b.9511be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1210,"y":140,"wires":},{"id":"bf47a416.7728b8","type":"function","z":"3e35e26b.9511be","name":"Insert Query","func":"msg.action = 'Insert';\n\nvar SCBASICSYNC = global.get('appconfig').oracledbschema + .
+ global.get('appconfig').tableSCBASICSYNC;\nnode.log("ramya")\nif (msg.payload) {\n node.log("msg.payload==>" + JSON.stringify(msg.payload))\n var lastupdated= msg.payload.dateoutput;\n //node.log("lastupdated===>", +lastupdated);\n var duedate = msg.payload.dueoutput;\n node.log("duedate===>", +duedate);\n\n var values = ('
+ msg.payload.ORDERBPMID + ','
+ msg.payload.ORDERNUMBER + ',
+ msg.payload.PARTYMASTID + ,\n '
+ msg.payload.PARTYMASTBMPID + ',
+ msg.payload.ITEMMASTERID + ,'
+ msg.payload.ITEMMASTERBPMID + ',\n '
+ msg.payload.UNIT + ',
+ msg.payload.QTY + ,'
+ msg.payload.ABCGRADE + ',
+ msg.payload.RATE + ,\n
+ msg.payload.AMOUNT + ,'
+ msg.payload.REMARKS + ',TO_TIMESTAMP('
+ duedate + ', 'YYYY-MM-DD HH24:MI:SS.FF'),\n '
+ msg.payload.ASTATUS + ','
+ msg.payload.USERCTRL + ','
+ msg.payload.SALETYPE + ','
+ msg.payload.SECTOR + ',\n
+ msg.payload.SCBASICID + ,'
+ msg.payload.CONTRACTDOCID + ','
+ msg.payload.CONTRACTBPMID + ',\n '
+ msg.payload.ORDSYNCSTATUS + ','
+ msg.payload.ITEMID + ','
+ msg.payload.ITEMDESC + ',\n
+ msg.payload.PRIUNIT + ,TO_TIMESTAMP('
+ lastupdated + ', 'YYYY-DD-MM HH24:MI:SS.FF'),\n '
+ msg.payload.PLANT + ',
+ msg.payload.BRANCHMASTID + ,
+ msg.payload.ORDERSYNCID + )\n
;\n\n var query = INSERT INTO
+ SCBASICSYNC + (ORDERBPMID, ORDERNUMBER, PARTYMASTID, PARTYMASTBMPID, ITEMMASTERID,\n ITEMMASTERBPMID, UNIT, QTY, ABCGRADE, RATE, AMOUNT, REMARKS, DUEDATE, ASTATUS, USERCTRL, SALETYPE, SECTOR, SCBASICID,\n CONTRACTDOCID, CONTRACTBPMID,ORDSYNCSTATUS,ITEMID,ITEMDESC,PRIUNIT,LASTUPDATED,PLANT,BRANCHMASTID,ORDERSYNCID) VALUES
+ values;\n\n msg.payload.query = query;\n node.log("queryResult===>", msg.payload.query);\n \n\n}\n return msg;\n","outputs":1,"noerr":0,"x":470,"y":660,"wires":[["e6f658b3.71c228","4e2cee2f.ec4fe"]]},{"id":"e6f658b3.71c228","type":"debug","z":"3e35e26b.9511be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":670,"y":600,"wires":},{"id":"4e2cee2f.ec4fe","type":"oracle-db","z":"3e35e26b.9511be","name":"","x":810,"y":720,"wires":[["91a22547.f64da8","5abb8d6f.4f3b14"]]},{"id":"7c4d25a9.b3416c","type":"http response","z":"3e35e26b.9511be","name":"Response","statusCode":"200","headers":{},"x":1020,"y":860,"wires":},{"id":"91a22547.f64da8","type":"function","z":"3e35e26b.9511be","name":"Set response","func":"node.log("action========>" + msg.action);\nvar res = {};\n\nvar message ='';\n\nmessage = msg.action == 'Insert' ? 'Order Inserted succesfully':'Order Updated Succesfully'\n\nres.status = 'success';\n\nres.message = message\nnode.log("res.message==>" + res.message);\nmsg.payload = res;\n\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":720,"wires":[["7c4d25a9.b3416c","1d3c4ea3.d135a1"]]},{"id":"5abb8d6f.4f3b14","type":"debug","z":"3e35e26b.9511be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":910,"y":620,"wires":},{"id":"f6591c7a.8b4a7","type":"function","z":"3e35e26b.9511be","name":"Update Query","func":"node.log("ramya111111111")\nmsg.action = 'Update';\n\nvar SCBASICSYNC = global.get('appconfig').oracledbschema + .
+ global.get('appconfig').tableSCBASICSYNC;\n\nif (msg.payload) {\n node.log("raamya111111")\n var lastupdated= msg.payload.dateoutput;\n // node.log("lastupdated===>", +lastupdated);\n var duedate = msg.payload.dueoutput;\n \n msg.payload.query = '';\n\n var query = UPDATE
+ SCBASICSYNC + SET ORDERNUMBER ='
+ msg.payload.ORDERNUMBER + ', \n PARTYMASTID = '
+ msg.payload.PARTYMASTID + ', PARTYMASTBMPID = '
+ msg.payload.PARTYMASTBMPID + ', ITEMMASTERID = '
+ msg.payload.ITEMMASTERID + ', \n ITEMMASTERBPMID = '
+ msg.payload.ITEMMASTERBPMID + ', UNIT = '
+ msg.payload.UNIT + ', QTY =
+ msg.payload.QTY + , \n ABCGRADE = '
+ msg.payload.ABCGRADE + ',\n RATE =
+ msg.payload.RATE + , AMOUNT =
+ msg.payload.AMOUNT + , REMARKS = '
+ msg.payload.REMARKS + ',\n DUEDATE = TO_TIMESTAMP('
+ duedate + ', 'YYYY-MM-DD HH24:MI:SS.FF'), \n ASTATUS = '
+ msg.payload.ASTATUS + ', USERCTRL = '
+ msg.payload.USERCTRL + ', SALETYPE = '
+ msg.payload.SALETYPE + ',\n SECTOR = '
+ msg.payload.SECTOR + ', SCBASICID = '
+ msg.payload.SCBASICID + ', CONTRACTDOCID = '
+ msg.payload.CONTRACTDOCID + ',\n CONTRACTBPMID = '
+ msg.payload.CONTRACTBPMID + ',ORDSYNCSTATUS = '
+ msg.payload.ORDSYNCSTATUS + ',\n ITEMID = '
+ msg.payload.ITEMID + ',ITEMDESC = '
+ msg.payload.ITEMDESC + ',\n PRIUNIT = '
+ msg.payload.PRIUNIT + ',LASTUPDATED = TO_TIMESTAMP('
+ lastupdated + ', 'YYYY-DD-MM HH24:MI:SS.FF'),\n PLANT = '
+ msg.payload.PLANT + ', BRANCHMASTID = '
+ msg.payload.BRANCHMASTID + ', ORDERSYNCID = '
+ msg.payload.ORDERSYNCID + '\n WHERE ORDERBPMID = '
+ msg.payload.ORDERBPMID + '
;\n \n\n msg.payload.query = query;\n\n return msg;\n\n}\n","outputs":1,"noerr":0,"x":460,"y":800,"wires":[["9189187b.463528","4e2cee2f.ec4fe"]]},{"id":"9189187b.463528","type":"debug","z":"3e35e26b.9511be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":630,"y":860,"wires":},{"id":"f66be923.8151e8","type":"switch","z":"3e35e26b.9511be","name":"Deciding Insert and Update","property":"responsedata.length","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"neq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":180,"y":740,"wires":[["bf47a416.7728b8"],["f6591c7a.8b4a7"]]},{"id":"520a80ae.3ad77","type":"debug","z":"3e35e26b.9511be","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1070,"y":380,"wires":},{"id":"50af73f8.8a1f9c","type":"debug","z":"3e35e26b.9511be","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":160,"y":60,"wires":},{"id":"b22bcad8.deacc8","type":"debug","z":"3e35e26b.9511be","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":750,"y":500,"wires":},{"id":"e1c26a14.db41a8","type":"moment","z":"3e35e26b.9511be","name":"","topic":"","input":"","inputType":"date","inTz":"Asia/Calcutta","adjAmount":0,"adjType":"hours","adjDir":"add","format":"YYYY-DD-MM HH:mm:ss","locale":"en_US","output":"payload.dateoutput","outputType":"msg","outTz":"Asia/Calcutta","x":820,"y":380,"wires":[["520a80ae.3ad77","6525df9c.73d06","6525df9c.73d06"]],"outputLabels":["YYYY DD MM HH:mm:ss"]},{"id":"6525df9c.73d06","type":"moment","z":"3e35e26b.9511be","name":"","topic":"","input":"payload.DUEDATE","inputType":"msg","inTz":"Asia/Calcutta","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD HH:mm:ss","locale":"en_US","output":"payload.dueoutput","outputType":"msg","outTz":"Asia/Calcutta","x":480,"y":500,"wires":[["b22bcad8.deacc8","f66be923.8151e8"]]},{"id":"1d3c4ea3.d135a1","type":"debug","z":"3e35e26b.9511be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1220,"y":680,"wires":}]