Getting Error : Violations Found. Code is not saved ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 06:40 AM
(function() {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 07:59 AM - edited 05-26-2025 08:00 AM
Currently you've written all your children functions inside the main function, so move all the children functions outside the main function. Also, while calling the child function use this keyword in front of the function name.
Ex:
var hasChildrenWithName = this.hasChildWithName(child.sys_id,filter);
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 10:46 PM
Not working !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 11:36 PM
try this
function getAllChildren(parentId, filter) {
var result = [];
var toProcess = [parentId];
while (toProcess.length > 0) {
var currentParentId = toProcess.pop();
var childGR = new GlideRecord('cmn_department');
childGR.addQuery('parent', currentParentId);
childGR.orderBy('name');
childGR.query();
while (childGR.next()) {
var childName = childGR.getValue('name');
if (!filter || childName.toLowerCase().indexOf(filter) >= 0) {
result.push({
label: childName,
id: childGR.getValue('sys_id'),
depID: childGR.getValue('id'),
collapsed: true // or false, as needed
});
// Add this child's sys_id to the stack to process its children
toProcess.push(childGR.getValue('sys_id'));
}
}
}
return result;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 11:45 PM
Not working, Basically the code which I have pasted in question. The same code running correctly in my PDI but in my Dev instance that is not working.