Zoran Roncevic
12/10/2020, 7:47 AMPNJ
12/10/2020, 7:50 AMZoran Roncevic
12/10/2020, 7:54 AMPNJ
12/10/2020, 8:04 AMZoran Roncevic
12/10/2020, 8:13 AMZoran Roncevic
12/10/2020, 8:36 AM/**
* @NApiVersion 2.0
* @NScriptType bankStatementParserPlugin
*/
define([ "N/xml", "N/log", "N/runtime", "N/email", "N/query" ], function(xml, log, runtime, email, query) {
// Returns value from first node found by tag name
function getValueFromNodeByTagName(xmlDocument, tagName) {
var elements = xml.XPath.select({
node : xmlDocument,
xpath : "//" + tagName
});
return elements[0].textContent;
}
// Returns array of nodes found by tag name
function getNodesByTagName(xmlDocument, tagName) {
var elements = xml.XPath.select({
node : xmlDocument,
xpath : "//" + tagName
});
return elements;
}
// Returns value of a node
function getValueFromNode(node) {
return node.textContent;
}
return {
parseBankStatement : function(context) {
var xmlString = context.input.file.getContents();
try {
var xmlDocument = xml.Parser.fromString({
text : xmlString
});
/* Removed rest of script ... not relevant */
var fitids = getNodesByTagName(xmlDocument, "fitid");
for (var i = 0; i < trnlistCount; i++) {
if (fitids[i].textContent) {
/*
Here are we go into problem ... each line have query.
*/
var sql_type = " select tranid as v_tranid, type as v_type from transaction where custbody_rsm_bdp_bankref = ? ";
var results_type = query.runSuiteQL({
query : sql_type,
params : [ fitids[i].textContent ]
});
var objdata = results_type.asMappedResults();
if (objdata.length > 0) {
if (objdata[0]["v_type"] == "CustDep") {
transaction.transactionNumber = objdata[0]["v_tranid"];
}
if (objdata[0]["v_type"] == "CustPymt") {
transaction.transactionNumber = "# " + objdata[0]["v_tranid"];
}
}
}
context.output.addTransaction({
parsedTransaction : transaction
});
}
} catch (e) {
var userEmail = runtime.getCurrentUser().email;
email.send({
author : -5,
recipients : userEmail,
subject : "Greska prilikom upload-a dnevnog izvoda banke",
body : "Doslo je do greske prilikom parsiranja dnevnog izvoda banke. Proverite encoding fajla (mora biti UTF-8).\n" + "Takodje, proverite da li se broj racuna vase firme u sistemu podudara sa brojem racuna u fajlu.\n\n"
+ "Error message:" + e.toString()
});
}
},
getStandardTransactionCodes : function(context) {
/* Removed code */
}
};
});
michoel
12/10/2020, 8:55 AMPNJ
12/10/2020, 8:56 AM