Comparing variable references to the department table against a user's department table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
I've got a catalogue item where a user can input new different departments into an existing business application:
What I'm wanting to add is check if the path to the current Business Owner's department aligns to the proposed Business Owning Business Unit/Function or Business Owning Platform. If it doesn't then inform the user that the current business owner does not sit within the proposed Business owning Business Unit and/or Platform.
The 'New Business Owning Business Unit or Function' displays options where the Department type is 'Function' or 'Business Unit' and 'New Business Owning Platform' displays options where the Department type is 'Platform'. I was just wondering if anyone has come across this before or something similar.
Generally, a a department with a type of 'Platform' is usually a child of a department with a type of 'Business Unit' or 'Function'. However, though, it can sometimes be that the grandchild department has a type of 'Platform', the parent department has a type of null, but the grandparent has a type of 'Business Unit' or 'Function'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Yes my Friend — this is a fairly common requirement, and you’re thinking about it the right way for sure!
The simplest and most reliable approach is to validate the department hierarchy server-side, not just the immediate department:
Get the current Business Owner’s department
Walk up the cmn_department.parent chain
Identify the nearest ancestor with type Business Unit / Function and (if applicable) Platform
Compare those to the user-selected New Business Owning BU/Function and Platform
Because your hierarchy can have “null ” levels you need to traverse upward until a typed department is found, not assume parent = BU or Platform.
I would recommended pattern:
Catalog onChange Client Script (or onSubmit)
Call a GlideAjax Script Include to evaluate the hierarchy
If it doesn’t align, show a message and optionally block submission
Reference qualifiers are very useful for limiting selectable values, but this kind of cross-field hierarchy validation is much more reliable with the server-side check.
@matthew_hughes - Please give a thumbs up or accepted solution if you feel it was Helpful!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
34m ago
Hi @Matthew_13 Do you have an example of how I would implement a script include/function to look up the hierarchy of a department?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
24m ago
Sure my Friend — here’s a short, practical example that shows the core idea without extra scaffolding.
This Script Include walks up the cmn_department parent chain and returns the first BU/Function and Platform it finds.
var DeptHierarchyUtil = Class.create();
DeptHierarchyUtil.prototype = {
initialize: function () {},
getAncestors: function (deptSysId) {
var TYPE_FIELD = "u_type"; // update to your field
var MAX_DEPTH = 20;
var result = {
bu_or_function: null,
platform: null
};
var current = deptSysId;
var depth = 0;
while (current && depth < MAX_DEPTH) {
var d = new GlideRecord("cmn_department");
if (!d.get(current)) break;
var type = d.getValue(TYPE_FIELD);
if (!result.bu_or_function && (type === "Business Unit" || type === "Function")) {
result.bu_or_function = d.getUniqueValue();
}
if (!result.platform && type === "Platform") {
result.platform = d.getUniqueValue();
}
current = d.getValue("parent");
depth++;
}
return result;
},
type: "DeptHierarchyUtil"
};
And Usage (server-side):
var util = new DeptHierarchyUtil();
var info = util.getAncestors("<department_sys_id>");
Please call this from a GlideAjax Script Include and compare returned BU/Platform to the user’s selections then block submission or show a message if they don’t align.
@matthew_hughes - Please give a thumbs up or accepted solution if you feel it was Helpful!