Getting Error : Violations Found. Code is not saved ServiceNow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 06:40 AM
I am getting Error : Violations Found. Code is not saved ServiceNow in below code while saving the Widget form.
(function() {
(function() {
data.pageSize = 500;
var dep = new GlideRecord('cmn_department');
if (input.id) {
//Get selected departments;
var sys_ids = [];
var labels = [];
var label = '';
var selected = new GlideRecord('cmn_department');
selected.addQuery('sys_id','IN',input.selected).addOrCondition('sys_id','IN',input.id);
selected.orderBy('name');
selected.query();
while (selected.next()) {
label = selected.name.toString();
label = label.replace(/,/g,","); //Replace all commas with character code "," so we can make a comma seperated list
labels.push(label);
sys_ids.push(selected.sys_id.toString());
}
data.sys_ids = sys_ids.join();
data.labels = labels.join();
return;
}
if (input.page) {
data.treedata = [];
var filter = input.filter.toLowerCase();
if (filter)
data.pageSize = 500;
var page = input.page - 1; //We want to be 0 indexed
var start = (page * data.pageSize);
var end = ((page + 1) * data.pageSize);
dep.addNullQuery('parent');
dep.orderBy('name');
dep.chooseWindow(start, end,true);
dep.query();
if (!filter)
data.count = dep.getRowCount();
else
data.count = 0;
//console.log("Count " + data.count + " / " + data.pageSize);
while (dep.next()) {
var sys_id = dep.getValue('sys_id');
var name = dep.getValue('name');
var gr = new GlideRecord('cmn_department');
//Only show if a child down below contains the search string in the name
if (filter) {
var hasChildrenWithName = hasChildWithName(dep.sys_id,filter);
if (!hasChildrenWithName)
continue;
}
gr.get(sys_id);
var node = {};
node.label = name;
node.id = sys_id;
node.depID = gr.getValue('id');
node.children = findChildren(gr,filter,false);
if (!filter && name.indexOf('Topdanmark') != 0) //Collapse tree if showing full tree view
node.collapsed = true;
data.treedata.push(node);
data.count++;
}
}
function inObject(objects,property,toSearch) {
var found = false;
if (objects.length == 0)
return false; //No need to search an empty object
for(var i=0; i<objects.length; i++) {
for(var key in objects[i]) {
if(objects[i][property][key].indexOf(toSearch)!=-1) {
found = true;
}
}
}
return found;
}
function getTopLevel(child_id) {
var dep = new GlideRecord('cmn_department');
dep.get(child_id);
if (dep.parent.parent == '')
return dep.parent;
return getTopLevel(dep.parent);
}
function hasChildWithName(depID,filter) {
var hasChilds = false;
var dep = new GlideRecord('cmn_department');
dep.get(depID);
var child = new GlideRecord('cmn_department');
child.addQuery('parent',dep.sys_id);
child.query();
hasChilds = child.hasNext();
if (!hasChilds)
return false;
child.initialize(); //reset gr
child.addQuery('parent',dep.sys_id);
child.orderBy('name');
child.query();
while (child.next()) {
if (child.name.toLowerCase().indexOf(filter) >= 0)
return true;
if (hasChildWithName(child.sys_id,filter))
return true;
}
return false;
}
function findChildren(parent,filter,expand) {
var result = [];
var child = new GlideRecord('cmn_department');
child.addQuery('parent',parent.sys_id);
child.orderBy('name');
child.query();
while (child.next()) {
var filterMatch;
if (filter)
filterMatch = child.name.toLowerCase().indexOf(filter);
//Only show if a this child or child down below contains the search string in the name
if (filter && filterMatch == -1) {
var hasChildrenWithName = hasChildWithName(child.sys_id,filter);
if (!hasChildrenWithName)
continue;
}
var node = {};
node.label= child.getValue('name');
node.id = child.getValue('sys_id');
node.depID = child.getValue('id');
if (!filter && !expand) //Collapse tree if showing full tree view
node.collapsed = true;
if (filterMatch >=0)
node.children = findChildren(child,'',true); //Show all childs if this child matches the filter
else
node.children = findChildren(child,filter,false);
result.push(node);
}
return result;
}
})();
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 11:51 PM
strange.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader