ServiceNow DataStream parse error "com.snc.process_flow.stream.SplittingDatastream"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I am facing an error while using DataStream action during Parser step.
Error:attached
class java.lang.String cannot be cast to class com.snc.process_flow.stream.SplittingDatastream (java.lang.String is in module java.base of loader 'bootstrap'; com.snc.process_flow.stream.SplittingDatastream is in unnamed module of loader
According to my Data stream use case, i want to call REST API with the REST Step, and i will be downloading an CSV File as a response body. I would want to parse the file and format it, update in a staging table.
my line of code in the parser step looks like this.
(function parse(request, response) {
var csvContent = request.body.data;
gs.info ('CSV Data' + csvContent);
if (!csvContent || typeof csvContent !== 'string') {
throw new Error("Expected CSV content as string in request.body.data");
}
var lines = csvContent.split('\n');
var rawHeader = lines[0].split(',');
var header = [];
for (var h = 0; h < rawHeader.length; h++) {
header.push(rawHeader[h].replace(/"/g, '').trim());
}
var fieldMap = {
'binary.name': 'Binaryname',
'binary.last_seen': 'Lastused',
'binary.product_name': 'Productname',
'device.name': 'Devicename',
'user.name': 'Username',
'device.hardware.model': 'Devicehardwaremodel',
'device.hardware.type': 'Devicehardwaretype',
};
for (var i = 1; i < lines.length; i++) {
var row = lines[i].trim();
if (!row) continue;
var fields = row.split(',');
var record = {};
for (var j = 0; j < header.length; j++) {
var csvHeader = header[j].trim();
var fieldName = fieldMap[csvHeader];
var fieldValue = fields[j] ? fields[j].replace(/"/g, '').trim() : '';
if (fieldName) {
record[fieldName] = fieldValue;
}
}
if (Object.keys(record).length > 0) {
response.stream.write(record); // ✅ This is an object, not a string
}
}
})(request, response);
and i will attach the datastream steps.
I don't need a splitter step because my output or responsebody from rest step is a CSV file and splitter step only supports either jso/xml format.
My question is, Not using splitter step will cause any issues like the error that i highlighted? or is it mandatory to have splitter step?
From google source, according to the error, it says, its expecting a string!!
So, i have only possibility to get the API Call to download a CSV file.
Is there any way or code suggestions to read/convert my response body into String before i parse? or any experts of data stream, help me with the situation!!