Invalid flags supplied to regexp constructor jgi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 08:35 AM - edited 10-25-2023 08:41 AM
Hello.
Any idea what is this please? Google was not helpful 😞
I have this part of the code:
var reg = new RegExp("[A-Za-z0-9-_ ,().\/']", 'jgi');
var f = encodeMe(info[i].split("::")[1].replace('\r', '').replace('"', ''));
var val = f.replace(reg, '');
Error is:
I suppose this is the issue because looks like this part of the code is cleaning for me infoJS.BBBBcode and we do not know why.... code is older then us...
I added logs there and I see after 10th iteration the infoJS.BBBBcode is getting cleaned somehow in the line 50 51 52 of the code below:
infoJS.BBBBcode = encodeMe(current.cmdb_ci.u_vvv_cmdb_ci_hardware_barcoderfid);
Whole code is here:
(function executeRule(current, previous /*null when async*/ ) {
try {
//Attachment
var attachment = new Attachment();
var getBranchCodeAbsolute = "";
var getBranchOpenDaysAbolute = "";
var fileName = "VVV_" + current.number + "_" + gs.nowDateTime() + '.xml';
var getBranchCode = new GlideRecord("cmn_department");
getBranchCode.addQuery("id", current.cmdb_ci.u_vvv_cmdb_ci_hardware_assignmentbusinessunitid);
getBranchCode.setLimit(1);
getBranchCode.query();
if (getBranchCode.next()) {
gs.log("Print from BBBB business rule" + getBranchCode.u_vvv_deptbranch.getDisplayValue());
getBranchCodeAbsolute = getBranchCode.u_vvv_deptbranch.u_branch.u_vvv_branch_branchcode;
getBranchOpenDaysAbolute = getBranchCode.u_vvv_deptbranch.u_branch.u_vvv_branch_opendays;
}
var content_type = 'text/xml';
var infoJS = {};
infoJS.Hostname = encodeMe(current.cmdb_ci.u_vvv_cmdb_ci_hardware_assethostname);
infoJS.BBBBcode = encodeMe(current.cmdb_ci.u_vvv_cmdb_ci_hardware_barcoderfid);
//infoJS.BBBBcode is getting cleaned in 10th iteration in the line 50 51 52
gs.log("BBBB Barcode - step 1 - UPDATE - get barcode: " + current.number + "\n" + infoJS.BBBBcode);
infoJS.SerialNumber = encodeMe(current.cmdb_ci.serial_number);
infoJS.ServerName = '';
infoJS.Model = encodeMe(current.cmdb_ci.u_vvv_cmdb_ci_hardware_modelname);
infoJS.Country = encodeMe(current.cmdb_ci.location.country);
infoJS.Region = encodeMe(current.cmdb_ci.location.state);
infoJS.City = encodeMe(current.cmdb_ci.location.city);
infoJS.Site = encodeMe(current.cmdb_ci.location.street);
infoJS.District = encodeMe(current.cmdb_ci.location.u_vvv_location_district);
infoJS.Building = '';
infoJS.Floor = '';
infoJS.Room = '';
infoJS.Workspace = '';
infoJS.Address = encodeMe(current.cmdb_ci.location.street);
infoJS.type = encodeMe(current.cmdb_ci.category) + "\\" + encodeMe(current.cmdb_ci.u_vvv_cmdb_ci_hardware_assetnaturegroup) + "\\" + encodeMe(current.cmdb_ci.u_vvv_cmdb_ci_hardware_assetnaturename);
try {
if (!gs.nil(current.u_vvv_additional_information)) {
var info = current.u_vvv_additional_information.split('\n');
for (var i = 0; i < info.length; i++) {
if (!gs.nil(info[i]) && info[i].indexOf("::") > -1 && !gs.nil(info[i].split("::")[1].replace('"', ''))) {
var reg = new RegExp("[A-Za-z0-9-_ ,().\/']", 'jgi');
var f = encodeMe(info[i].split("::")[1].replace('\r', '').replace('"', ''));
var val = f.replace(reg, '');
if (gs.nil(val))
infoJS[info[i].split("::")[0].replace('"', '')] = f;
else {
for(var x = 0; x < val.length; x++) {
if(val[x] != '&' && val[x] != ';')
f = f.replaceAll(val[x], "");
}
}
infoJS[info[i].split("::")[0].replace('"', '')] = f;
if (info[i].split("::")[0].replace('"', '') == "City" && !gs.nil(infoJS.City)) {
var loc = new GlideRecord("cmn_location");
loc.addEncodedQuery("u_vvv_location_districtISNOTEMPTY^city=" + info[i].split("::")[1].replace('\r', '').replace('"', ''));
loc.query();
var check = false;
var long_district = '';
while (loc.next() && !check) {
if(loc.u_vvv_location_district.toString().length < 4) {
infoJS.District = loc.u_vvv_location_district.toString();
check = true;
} else if(long_district == '')
long_district = loc.u_vvv_location_district.toString();
}
if(gs.nil(infoJS.District))
infoJS.District = long_district;
}
}
}
}
} catch (e) {
gs.error("XML creation error: " + e);
}
}
var fileBytes = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ticket number=\"" + encodeMe(current.number) + "\" severity=\"\" status=\"" + encodeMe(current.state.getDisplayValue()) + "\" type=\"" + encodeMe(current.subcategory) + "\">" + "\n" +
"<title>" + encodeMe(current.short_description) + "</title>" + "\n" +
"<description>" + encodeMe(current.description) + "</description>" + "\n" +
"<update-history/>" + "\n" +
"<resolution>" + "\n" +
"<description/>" + "\n" +
"</resolution>" + "\n" +
"<ci asset-bbbbcode=\"" + infoJS.BBBBcode + "\" asset-tag=\"" + encodeMe(current.cmdb_ci.asset_tag) + "\">" + "\n" +
"<hostname>" + infoJS.Hostname + "</hostname>" + "\n" +
"<servername/>" + "\n" +
"<model>" + infoJS.Model + "</model>" + "\n" +
"<branch-code>" + encodeMe(getBranchCodeAbsolute) + "</branch-code>" + "\n" +
"<branch-opendays>" + encodeMe(getBranchOpenDaysAbolute) + "</branch-opendays>" + "\n" +
"<serial-number>" + infoJS.SerialNumber + "</serial-number>" + "\n" +
"<type>" + infoJS.type + "</type>" + "\n" +
"<address>" + infoJS.Address + "</address>" + "\n" +
"<city>" + infoJS.City + "</city>" + "\n" +
"<district>" + infoJS.District + "</district>" + "\n" +
"<zip/>" + "\n" +
"<state>" + infoJS.Region + "</state>" + "\n" +
"<country>" + infoJS.Country + "</country>" + "\n" +
"<location>" + "\n" +
"<country>" + infoJS.Country + "</country>" + "\n" +
"<country-region>" + infoJS.Country + "</country-region>" + "\n" +
"<zip/>" + "\n" +
"<district>" + infoJS.District + "</district>" + "\n" +
"<city>" + infoJS.City + "</city>" + "\n" +
"<address>" + infoJS.Address + "</address>" + "\n" +
"<site>" + infoJS.Site + "</site>" + "\n" +
"<building>" + infoJS.Building + "</building>" + "\n" +
"<floor>" + infoJS.Floor + "</floor>" + "\n" +
"<room>" + infoJS.Room + "</room>" + "\n" +
"<workspace>" + infoJS.Workspace + "</workspace>" + "\n" +
"</location>" + "\n" +
"</ci>" + "\n" +
"<contact userid=\"" + encodeMe(current.caller_id.getDisplayValue()) + "\">" + "\n" +
"<name>" + encodeMe(current.caller_id.u_vvv_full_name) + "</name>" + "\n" +
"<phone>" + encodeMe(current.u_qs_contact_number) + "</phone>" + "\n" +
"<email>" + encodeMe(current.caller_id.email) + "</email>" + "\n" +
"<company>" + encodeMe(current.company.getDisplayValue()) + "</company>" + "\n" +
"</contact>" + "\n" +
"<open-time>" + encodeMe(current.opened_at) + "</open-time>" + "\n" +
"<update-time>" + encodeMe(current.sys_updated_on) + "</update-time>" + "\n" +
"<other-information>" + encodeMe(current.description) + "</other-information>" + "\n" +
"</ticket>";
// var newFileBytes = encodeMe(fileBytes);
attachment.write('incident', current.sys_id, fileName, content_type, fileBytes);
} catch (e) {
gs.error("XML creation error: " + e);
}
function encodeMe(myString) {
if (gs.nil(myString))
return '';
var mystring = myString.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
return mystring;
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 01:46 PM
I don't claim to be a regex wizard, but I think `j` is not a valid regex flag. Source: Regular expressions - JavaScript | MDN (mozilla.org)