
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 11:48 PM - edited 12-12-2023 12:37 AM
Hi All,
I am getting below best practice error. I used "Packages.java.lang.String(bytesInFile)" in BR script.
Best Practice Warning: brni_BPE10482 Checks for direct calls to Java packages
Required to run the Package Call Removal Tool, and replace all Java package calls with the Glide alternative.
(function executeRule(current, previous /*null when async*/ ) {
var comment = current.variables.u_comment.toString(); // get the value of Comment from catalog item
var ritmNumber = current.number; // get the value of RITM number
// get the attachment record from the current RITM
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', 'sc_req_item');
attachmentGR.addQuery('table_sys_id', current.sys_id);
attachmentGR.addQuery('file_name', 'CONTAINS', '.csv');
attachmentGR.query();
if (attachmentGR.next()) {
var gsa = new GlideSysAttachment();
var tableName = attachmentGR.getValue('table_name');
var sysId = attachmentGR.getValue('table_sys_id');
var bytesInFile = gsa.getBytes(tableName, sysId);
var originalContentsInFile = Packages.java.lang.String(bytesInFile);
originalContentsInFile = String(originalContentsInFile);
var rows = originalContentsInFile.split('\n');
var columnA = [];
for (var i = 1; i < rows.length; i++) { // start from index 1 to skip the header row
var columns = rows[i].split(',');
columnA.push(columns[0]);
}
var concatenatedDeviceID = columnA.join(',');
// gs.print("Data in Column A concatenatedDeviceID : " + concatenatedDeviceID);
var ci = new GlideRecord('cmdb_ci_hardware');
ci.addQuery('serial_number', 'IN', concatenatedDeviceID.split(","));
ci.query();
// var count = ci.getRowCount();
// gs.info('Found ' + count + ' hardware records with serial numbers ' + concatenatedDeviceID);
while (ci.next()) {
var workNotes = ci.getValue('u_work_notes'); // get the existing work_notes value
var newWorkNotes = "RITM number: " + ritmNumber;
if (comment) {
newWorkNotes += "\nComment: " + comment; // add the comment to the work_notes value if provided
}
// gs.print("work_notes : " + newWorkNotes);
// set newNotes as the journal entry for u_work_notes
var field = ci.u_work_notes;
field.setJournalEntry(newWorkNotes);
ci.update(); // save the changes
}
// gs.print("Records Updated in cmdb_ci_hardware.");
} //else {
// gs.print("No matching records found in cmdb_ci_hardware.");
// }
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 01:55 AM
Hi @Community Alums
in your first code you wanted to load a CSV file which is text based and that was the reason for my solution. Now you want to load an Excel file which is a native and binary format. Here my approach will not work. You really should be clear in your issue description and requirement!
So please have a take a look at the GlideExcelParser API which provides a way to extract data from Excel files.
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:06 AM
Can you share the full script to see where you have used a Java package call? As mentioned, it generally not be required and you should be using ServiceNow classes instead, depending on your use case.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:32 AM - edited 12-12-2023 12:34 AM
Hi @Laszlo Balla , BR full script is as follows:
See var originalContentsInFile = Packages.java.lang.String(bytesInFile);
(function executeRule(current, previous /*null when async*/ ) {
var comment = current.variables.u_comment.toString(); // get the value of Comment from catalog item
var ritmNumber = current.number; // get the value of RITM number
// get the attachment record from the current RITM
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', 'sc_req_item');
attachmentGR.addQuery('table_sys_id', current.sys_id);
attachmentGR.addQuery('file_name', 'CONTAINS', '.csv');
attachmentGR.query();
if (attachmentGR.next()) {
var gsa = new GlideSysAttachment();
var tableName = attachmentGR.getValue('table_name');
var sysId = attachmentGR.getValue('table_sys_id');
var bytesInFile = gsa.getBytes(tableName, sysId);
var originalContentsInFile = Packages.java.lang.String(bytesInFile);
originalContentsInFile = String(originalContentsInFile);
var rows = originalContentsInFile.split('\n');
var columnA = [];
for (var i = 1; i < rows.length; i++) { // start from index 1 to skip the header row
var columns = rows[i].split(',');
columnA.push(columns[0]);
}
var concatenatedDeviceID = columnA.join(',');
// gs.print("Data in Column A concatenatedDeviceID : " + concatenatedDeviceID);
var ci = new GlideRecord('cmdb_ci_hardware');
ci.addQuery('serial_number', 'IN', concatenatedDeviceID.split(","));
ci.query();
// var count = ci.getRowCount();
// gs.info('Found ' + count + ' hardware records with serial numbers ' + concatenatedDeviceID);
while (ci.next()) {
var workNotes = ci.getValue('u_work_notes'); // get the existing work_notes value
var newWorkNotes = "RITM number: " + ritmNumber;
if (comment) {
newWorkNotes += "\nComment: " + comment; // add the comment to the work_notes value if provided
}
// gs.print("work_notes : " + newWorkNotes);
// set newNotes as the journal entry for u_work_notes
var field = ci.u_work_notes;
field.setJournalEntry(newWorkNotes);
ci.update(); // save the changes
}
// gs.print("Records Updated in cmdb_ci_hardware.");
} //else {
// gs.print("No matching records found in cmdb_ci_hardware.");
// }
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:07 AM
Hi @Community Alums
please provide more information and context to help us understand you better.
It is not clear what you want to achieve when using Packages.java.lang.String(binData) as the rest of the code and the underlying use case is missing
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:38 AM
Hi @Maik Skoddow , BR full script is as follows:
See var originalContentsInFile = Packages.java.lang.String(bytesInFile);
(function executeRule(current, previous /*null when async*/ ) {
var comment = current.variables.u_comment.toString(); // get the value of Comment from catalog item
var ritmNumber = current.number; // get the value of RITM number
// get the attachment record from the current RITM
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', 'sc_req_item');
attachmentGR.addQuery('table_sys_id', current.sys_id);
attachmentGR.addQuery('file_name', 'CONTAINS', '.csv');
attachmentGR.query();
if (attachmentGR.next()) {
var gsa = new GlideSysAttachment();
var tableName = attachmentGR.getValue('table_name');
var sysId = attachmentGR.getValue('table_sys_id');
var bytesInFile = gsa.getBytes(tableName, sysId);
var originalContentsInFile = Packages.java.lang.String(bytesInFile);
originalContentsInFile = String(originalContentsInFile);
var rows = originalContentsInFile.split('\n');
var columnA = [];
for (var i = 1; i < rows.length; i++) { // start from index 1 to skip the header row
var columns = rows[i].split(',');
columnA.push(columns[0]);
}
var concatenatedDeviceID = columnA.join(',');
// gs.print("Data in Column A concatenatedDeviceID : " + concatenatedDeviceID);
var ci = new GlideRecord('cmdb_ci_hardware');
ci.addQuery('serial_number', 'IN', concatenatedDeviceID.split(","));
ci.query();
// var count = ci.getRowCount();
// gs.info('Found ' + count + ' hardware records with serial numbers ' + concatenatedDeviceID);
while (ci.next()) {
var workNotes = ci.getValue('u_work_notes'); // get the existing work_notes value
var newWorkNotes = "RITM number: " + ritmNumber;
if (comment) {
newWorkNotes += "\nComment: " + comment; // add the comment to the work_notes value if provided
}
// gs.print("work_notes : " + newWorkNotes);
// set newNotes as the journal entry for u_work_notes
var field = ci.u_work_notes;
field.setJournalEntry(newWorkNotes);
ci.update(); // save the changes
}
// gs.print("Records Updated in cmdb_ci_hardware.");
} //else {
// gs.print("No matching records found in cmdb_ci_hardware.");
// }
})(current, previous);