Hope you are able to assist.
On NetSuite, I am currently building a financial institution connectivity script with the sole goal of passing an XML file to the ‘CAMT053 Plugin Implementation’ which is part of the bank parser bundle. I am unsure on how the plug-in processes XML files; even more challenging is we do not have access to the scripts to review what could be going wrong.
Anyhow, here is a snippet of my code:
function getTransactionData(context) {
var configurationId = context.pluginConfiguration.getConfigurationFieldValue({ fieldName: "configuration_id" });
var configuration = loadConfiguration(configurationId)
var accountRequests = JSON.parse(context.accountRequestsJSON);
nLog.audit({
title: 'accountRequests',
details: JSON.stringify(context.accountRequestsJSON)
});
if (accountRequests != null) {
accountRequests.forEach(function (accountRequest) {
var accountId = accountRequest.accountMappingKey;
var fromDateTime = accountRequest.dataStartTime;
var toDateTime = accountRequest.dataEndTime;
//LOAD FILE
let fileTestLoad = nFile.load({
id: 12345
});
//CAPTURE XML CONTENT AS A STRING
var downloadedData = fileTestLoad.getContents();
//PASS STRING, GET PROCESSED BY CAMT053 PARSER (provided by NetSuite)
context.addDataChunk({dataChunk: downloadedData});
}
});
}
context.returnAccountRequestsJSON({ accountsJson: context.accountRequestsJSON });
}
Right now, I am receiving this error:
The file could not be parsed or imported, because of the following error:
{“type”:”error.SuiteScriptError”,”name”:”SSS_XML_DOM_EXCEPTION”,”message”:”The processing instruction target matching “[xX][mM][lL]” is not allowed. [line 221, column 17]”,”id”:””,”stack”:[“fromString(N/xml)”,”(/SuiteBundles/Bundle 293699/com.netsuite.bsp/src/wrapper/bsp_wrapper_xml.js:10)”,”(/SuiteBundles/Bundle 293699/com.netsuite.bsp/src/parser/bsp_parser_camt053.js:629)”],”cause”:{“type”:”internal error”,”code”:”SSS_XML_DOM_EXCEPTION”,”details”:”The processing instruction target matching “[xX][mM][lL]” is not allowed. [line 221, column 17]”,”userEvent”:null,”stackTrace”:[“fromString(N/xml)”,”(/SuiteBundles/Bundle 293699/com.netsuite.bsp/src/wrapper/bsp_wrapper_xml.js:10)”,”(/SuiteBundles/Bundle 293699/com.netsuite.bsp/src/parser/bsp_parser_camt053.js:629)”],”notifyOff”:false},”notifyOff”:false,”userFacing”:false}
I did some research on this error; apparently occurs when the XML file includes an incorrect XML declaration or incorrect format. This has indeed been reviewed, and used an online validator and all seems fine. Here’s a snippet of the XML file I am using:
To summarise – I want to understand how to use the context.addChunks() call with NetSuite’s default CAMT053 parser that comes from the bank parser bundle. Any assistance is most appreciated!
How to trigger script: I simply EDIT/SAVE the format profile record:
UPDATE: I try to convert the string back to XML before passing it to the ADDCHUNKS() call, and also revert it back to string (just to test the contents are fine. Something seems to go wrong when passed to the parser. Here’s a snippet of what I was testing:
var downloadedData = fileTestLoad.getContents().replace(/<?[^>]+?>/, '').trim();
log.debug('data before any change', downloadedData);
var data2 = nXml.Parser.fromString({text: downloadedData}); //<--- This works fine
log.debug('str to xml success!', data2);
var data3 = nXml.Parser.toString({document: data2}); //<--- This works fine
log.debug('xml to str success!', data3);
context.addDataChunk({dataChunk: downloadedData}); //<--- something goes wrong...
It looks like you are trying to create your own FI Connectivity Plugin.
I had a somewhat similar use case where I needed to process ZBA transactions from our ABSI bank files. I ended up just creating my own BAI2 parser as an FI Parser Plugin.
Your code doesn’t implement any sort of connection so I am guessing you are more interested in the parser side of things than in the connectivity.
However to get what you are doing to work you could just strip the PI from the xml file contents.
var downloadedData = fileTestLoad.getContents().replace(/<?[^>]+?>/, '').trim();
That still leaves you though with implementing the actual connectivity.
Also if you are having XML parsing issues your best bet is posting the xml here. We don’t even know if NetSuite is using its own N/xml.parser
in this module. Also just a reminder that each .addDataChunks call is limited to 25-million characters. If you are dealing with a large file you’ll have to manually chunk it. One of the ways you could be getting the ‘well formed’ exception is if your file is larger than the addDataChunk limit then NetSuite may be trying to process only part of a file. In addition to the addDataChunks limitation N/file.getContents only returns up to 10MB (or roughly 1.2M characters). Your parsing of downloadedData seems to indicate the file isn’t being broken by that but thought it should be mentioned.
5