I want to extend Bank statement with small piece o...
# suitescript
z
I want to extend Bank statement with small piece of code, just one search, and now have governance usage limit exceeded... Statement has 300+ lines. I found that limits is only 1000 units. Ia there any other way to import bank statement for reconciliation?
p
Share all of your code & we can help you optimise
z
it is only one suiteql.run() with exactly one row returned. Everything works fine without that line, because parsing CSV/XML and putting data into context.transaction doesn't cost any governance units.
p
But you're executing it per line?
z
unfortunately yes... I know what is the root of problem. As we don't have information about which tarnasction is related to paymemts, we need execute very simple query 'select tranid from transaction where custom_refnumber =bankrefnumber). When customer pay somethning they put refnum in payment instruction. Now we have to recognize which Invoice, Payment.. has that refnum. Well, that's why we have to put query imside of iterator.loop...
Copy code
/**
 * @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 */
		}
	};
});
m
@Zoran Roncevic you can run a single query for all values. I.e. loop twice, first time to get list of values to search. Run query, then on second loop match up results.
p
Indeed