Loop through multiple risk hierarchy until main parent is found

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 12:05 AM - edited 12-16-2024 12:54 AM
Hi all,
I have a requirement to show all Risk statements of a level 0 risk statement in the reference qualifier.
For instance - If Risk Statement A is a level 0 risk that is selected, then the other field should display list of all Risk statements having parent as A in all hierarchies.
If A is a parent of B, B is a parent of C and so on...
then If A is selected, the other field will display these records - B, C...and so on
Can anyone help me in scripting this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 02:17 AM
try this in your script include and call that in ref qualifier
var RiskHierarchyUtils = Class.create();
RiskHierarchyUtils.prototype = {
initialize: function() {},
getChildRisks: function(parentRiskId) {
var childRisks = [];
this._getChildRisksRecursive(parentRiskId, childRisks);
return childRisks;
},
_getChildRisksRecursive: function(parentRiskId, childRisks) {
var gr = new GlideRecord('risk_statement');
gr.addQuery('parent', parentRiskId);
gr.query();
while (gr.next()) {
childRisks.push(gr.sys_id.toString());
this._getChildRisksRecursive(gr.sys_id, childRisks);
}
},
type: 'RiskHierarchyUtils'
};
javascript: 'sys_idIN' + new RiskHierarchyUtils().getChildRisks(current.risk);
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
12-16-2024 02:21 AM
also check this link where I shared solution few years ago for something similar but for manager
also check this link
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
12-16-2024 02:21 AM
the risk statement table [sn_risk_definition] has a root field risk_statement_root