Hi Everyone,
I have to read a CSV file form a directory, do some data validation and then send the valid rows to a CSV file (valid.csv) and errored rows to another CSV file (errored.csv). I have created one source transformer and two destination transformers in my channel. The source transformer validates the rows and sends an array of indexes of errored rows to both destination transformers. The first destination transformer outputs the valid rows on valid.csv and the second one on errored.csv. I am getting the following error when trying to output the valid rows in tmp object in destination transformer. I have set up an out bound message template. I am using Mirth 4.1.1.
DESTINATION TRANSFORMER CODE
//indexes of errored rows from source transformer
var errorIndices = new Array;
errorIndices = $('ErrorInd');
var numOfColumn = msg.row[0].children().length();
var a = 0;
//Adding valid rows
for(var i=0;i<msg['row'].length();i++)
{
if (errorIndices.includes(i) == false){
for(var j=1;j<=numOfColumn;j++){
var tmp;
tmp['row'][a]['column'+j] = msg['row'][i]['column'+j].toString();
a++;
}
}
}
ERROR:
SCRIPT SOURCE: TRANSFORMER
SOURCE CODE:
283: {
284: if (errorIndices.includes(i) == false){
285: for(var j=1;j<=numOfColumn;j++)
286: {
287: var tmp;
288: tmp['row'][a]['column'+j] = msg['row'][i]['column'+j].toString();
289: a++;
290:
291: }
292: }
LINE NUMBER: 288
DETAILS: TypeError: Cannot read property "row" from undefined
at 362ab486-cd1a-4405-a615-66dd64f020d4_JavaScript_Filter_Transformer_1:288 (doTransform)
at 362ab486-cd1a-4405-a615-66dd64f020d4_JavaScript_Filter_Transformer_1:468 (doScript)
at 362ab486-cd1a-4405-a615-66dd64f020d4_JavaScript_Filter_Transformer_1:470
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:235)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:187)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:114)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)
I can post the whole channel if required. Any help would be appreciated. Thanks.
I have to read a CSV file form a directory, do some data validation and then send the valid rows to a CSV file (valid.csv) and errored rows to another CSV file (errored.csv). I have created one source transformer and two destination transformers in my channel. The source transformer validates the rows and sends an array of indexes of errored rows to both destination transformers. The first destination transformer outputs the valid rows on valid.csv and the second one on errored.csv. I am getting the following error when trying to output the valid rows in tmp object in destination transformer. I have set up an out bound message template. I am using Mirth 4.1.1.
DESTINATION TRANSFORMER CODE
//indexes of errored rows from source transformer
var errorIndices = new Array;
errorIndices = $('ErrorInd');
var numOfColumn = msg.row[0].children().length();
var a = 0;
//Adding valid rows
for(var i=0;i<msg['row'].length();i++)
{
if (errorIndices.includes(i) == false){
for(var j=1;j<=numOfColumn;j++){
var tmp;
tmp['row'][a]['column'+j] = msg['row'][i]['column'+j].toString();
a++;
}
}
}
ERROR:
SCRIPT SOURCE: TRANSFORMER
SOURCE CODE:
283: {
284: if (errorIndices.includes(i) == false){
285: for(var j=1;j<=numOfColumn;j++)
286: {
287: var tmp;
288: tmp['row'][a]['column'+j] = msg['row'][i]['column'+j].toString();
289: a++;
290:
291: }
292: }
LINE NUMBER: 288
DETAILS: TypeError: Cannot read property "row" from undefined
at 362ab486-cd1a-4405-a615-66dd64f020d4_JavaScript_Filter_Transformer_1:288 (doTransform)
at 362ab486-cd1a-4405-a615-66dd64f020d4_JavaScript_Filter_Transformer_1:468 (doScript)
at 362ab486-cd1a-4405-a615-66dd64f020d4_JavaScript_Filter_Transformer_1:470
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:235)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:187)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:114)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)
I can post the whole channel if required. Any help would be appreciated. Thanks.
Comment