Hi all,
Below is my code.
Everything runs fine, but a I need to add a condition for this variable:
var AWBPlic = (f.AWBPlic);
*Condition: when reading this line *Condition: if the string does not contain “RI0” skip the whole line of text from the output file.
Any ideas?
Thanks,
fsh22
var origFileName = get(“fisiere”);
origFileName = origFileName.substring(0, origFileName.lastIndexOf(‘.’));
var fileLocation = get(“global.workDir”) + “\retur_csv\” + origFileName + “_” + get(“id_comanda”) + “_retur.csv”
var csvHeader = ‘letter_queue_id|awb|CEID|Client_name|letter_type|Curier|’;//cap de tabel pentru nr 3. infocod EOS STANDARD
var records = JSON.parse(Watch.ExpandString(“%c”));createFile(fileLocation, csvHeader);
for (var i = 0; i < records.length; i++) {
// fields to exportvar f = records[i].fields; // keep things clean. // wrap the export in quotes var letterQueue = (f.COLUMN1); //var cheie_secundara = wrappInQuotes(f.cheie_secundara); var AWBPlic = (f.AWBPlic); var CEID = (f.COLUMN15); var clientName = (f.COLUMN23); var letterType = (f.COLUMN44); var curier = "Posta Romana" // Create a line of text joined with the pipe character var lineOfText = [letterQueue, AWBPlic, CEID, clientName, letterType, curier].join('|'); // write the line of text to the fileOut appendFile(fileLocation, lineOfText); //go to newline for new text
};
var outputFile = Watch.SetVariable(“fileName”, fileLocation);
/* Helpers */
function appendFile(path, content) {
var fs = new ActiveXObject(‘Scripting.FileSystemObject’)
var file = fs.OpenTextFile(path, 8, true)
file.WriteLine(content)
file.Close()
}function get(name) { return typeof name === ‘number’ ? Watch.getJobInfo(name) : Watch.getVariable(name) }
function set(name, value) { typeof name === ‘number’ ? Watch.setJobInfo(name, value) : Watch.setVariable(name, value) }
function log(msg) { try { Watch.log(toString(msg), 2) } catch(e) { WScript.stdout.WriteLine(toString(msg)) } }
function err(msg) { try { Watch.log(toString(msg), 1) } catch(e) { WScript.stdout.WriteLine(toString(msg)) } }
function exp(string) { return Watch.expandString(string); }
function xml(string) { return Watch.expandString(“xmlget('/request[1]/values[1]/” + string + “[1]',Value,KeepCase,No Trim)”); }
function toString(value) { try { return JSON.stringify(value) } catch(e) { return ‘’+value } }function format() {
var as = arguments
return as[0].replace(/{ *(\w+) *}/g,
function(m, i) { return as[i] })
}function sanitizeFilename(filename) {
return filename.replace(//|\|:|?|*|"|||<|>/g, ‘-’)
}function writeFile(path, content){
var fs = new ActiveXObject(‘Scripting.FileSystemObject’)
var file = fs.OpenTextFile(path, 2, true)
file.Write(content)
file.Close()
}function createFile(path, content){
var fs = new ActiveXObject(“Scripting.FileSystemObject”)
var file = fs.CreateTextFile(path)
file.WriteLine(content)
file.Close()
}/**
- helper function to wrap text in quotes for escaping
- @param {string} text
*/
//function wrappInQuotes(text) {
// return ‘"’ + text + ‘"’
//};