Add subentities to Engagement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago - last edited 4 hours ago
(function executeRule(current, previous /*null when async*/) {
// Exit if no entity or engagement
if (current.sn_grc_profile.nil() || current.sn_audit_engagement.nil()) {
return;
}
var entityId = current.sn_grc_profile.toString();
var engagementId = current.sn_audit_engagement.toString();
// Get the entity record
var entityGR = new GlideRecord('sn_grc_profile');
if (!entityGR.get(entityId)) {
return;
}
// Only process if profile class is "Auditable Unit"
if (entityGR.profile_class.nil() || entityGR.profile_class != 'auditable_unit') {
return;
}
// Only process if entity has an auditable unit reference
if (entityGR.applies_to.nil()) {
return;
}
var auditableUnitId = entityGR.applies_to.toString();
// Check department M2M table for departments linked to this auditable unit
var deptM2M = new GlideRecord('sn_audit_m2m_auditable_unit_department');
deptM2M.addQuery('sn_audit_auditable_unit', auditableUnitId);
deptM2M.query();
while (deptM2M.next()) {
var departmentId = deptM2M.getValue('cmn_department');
if (!departmentId || gs.nil(departmentId)) {
continue;
}
// Find entities that have this department
var profile = new GlideRecord('sn_grc_profile');
profile.addQuery('cmn_department', departmentId);
profile.query();
while (profile.next()) {
var profileId = profile.sys_id.toString();
// Check if already linked to engagement
var existingLink = new GlideRecord('sn_audit_m2m_profile_engagement');
existingLink.addQuery('sn_audit_engagement', engagementId);
existingLink.addQuery('sn_grc_profile', profileId);
existingLink.query();
if (existingLink.hasNext()) {
continue; // Already linked, skip
}
// Add entity to engagement
var newLink = new GlideRecord('sn_audit_m2m_profile_engagement');
newLink.initialize();
newLink.sn_audit_engagement = engagementId;
newLink.sn_grc_profile = profileId;
newLink.insert();
}
}
})(current, previous);Hi everyone,
I need some guidance on an issue I’m facing with a Business Rule that is not working as expected.
My requirement is that when an entity of class Auditable Unit is added to an Engagement, there are some related subsections under the Auditable Unit such as departments and product vendors. These departments and product vendors are already linked to the Auditable Unit through an M2M table. system should check added belongs to which auditable unit and work accordingly/
As soon as the entity is added, I want the same departments and product vendors to be automatically added under the entity to engagement relationship record in the table sn_audit_m2m_profile_engagement. This is required so that we can combinely create risks and controls during the Validate and Plan state.
I have written an After Insert Business Rule that triggers when the Auditable Unit is added. In this Business Rule, I am trying to fetch the related departments and product vendors from the M2M table and insert corresponding records into sn_audit_m2m_profile_engagement.
However, the Business Rule is not working and the related records are not getting created.
I would like to know whether After Insert is the correct approach for this requirement, or if this logic should be handled using a Script Include or Flow instead. I also want to understand if there are any limitations or best practices when inserting records into sn_audit_m2m_profile_engagement. If anyone has implemented similar logic for Auditable Units and Engagements, your guidance would be really helpful.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hello,
Please check any existing On-Insert BR on M2M Profile Engagement table, which needs the mandatory fields to be filled before inserting any record.
There might be rules written on M2M tables which are blocking insert operation based on certain conditions,
So you can try searching like:
Script contains setAbortAction(true).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hello @ujjwalababa ,
What I will recommend is that Before Business Rule + Script Include is the most reliable approach.
Flow Designer is the most maintainable if your team is comfortable with it.
If my response helped mark as helpful and accept the solution.
