Display Risk Assessments in Audit Engagement Based on Associated Entities/Risks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hello everyone,
I'm working on integrating Audit Management with Risk Management and have run into an issue with creating a custom related list. I'm hoping someone here has dealt with something similar.
I'm trying to add a "Risk Assessments" tab to the Engagement form that displays only the relevant risk assessment instances. Specifically, I need to show risk assessments where the associated risk is one of the risks linked to that particular engagement, and the assessment has been published (state equals 2).
The engagement and risks are connected through a many-to-many table called sn_audit_m2m_risk_engagement. I've created a relationship in System Definition that applies to the engagement table and queries from the risk assessment instance table.
In my query script, I'm first gathering all the risk sys_ids associated with the current engagement by querying the many-to-many table. I then collect these risk IDs into an array and try to filter the risk assessment instances using an IN operator on the risk reference field, along with a condition for the published state.
The problem I'm facing is that the related list is displaying all risk assessment records instead of just the filtered ones. I've verified through logging that the risk list contains valid sys_ids, so the data is being retrieved correctly. However, the filtering doesn't seem to be applied when the related list renders.
Has anyone successfully implemented a similar relationship where you filter child records based on a many-to-many association? I'm wondering if there's something specific about how relationships handle reference field filtering, or if I should be approaching this differently altogether. Any guidance would be greatly appreciated. Thanks in advance for your help!
below is something I have tried,
(function refineQuery(current, parent) {
var riskList = [];
var grEngRisk = new GlideRecord('sn_audit_m2m_risk_engagement');
grEngRisk.addQuery('sn_audit_engagement', parent.getUniqueValue());
grEngRisk.query();
while (grEngRisk.next()) {
riskList.push(grEngRisk.getValue('sn_risk_risk'));
}
if (riskList.length > 0) {
current.addQuery('risk', 'IN', riskList.join(','));
current.addQuery('risk_assessment_methodology.state', '2');
} else {
current.addQuery('sys_id', 'NULL');
}
})(current, parent);
