Filtered List of Risks

vivek_f19
Tera Contributor

Hey All,

I have been stuck with a problem for a few days now and have decided to reach out to the community for some guidance. Here it is:

In the Issues form (sn_grc_issue), I created two Reference fields:
1. u_entity: Entity table - sn_grc_profile. 

2. u_risks: Risk Register table - sn_risk_risk.

 

Required behaviour: I need the Risks list to be filtered based on the Entity selected in the 'u_entity' field.

Here is what I have done so far, but it doesn't work:

Reference qualifier:

vivek_f19_0-1720792511348.png

Business Rule:

vivek_f19_1-1720792637119.png

BR Script: 

(function executeRule(current, previous /*null when async*/) {
    var entitySysId = current.u_entity;
    if (!entitySysId) {
        current.u_risks = ''; // Clear risks if entity is empty
        return;
    }
   
    var risks = [];
    var gr = new GlideRecord('sn_risk_risk');
    gr.addQuery('u_entity', entitySysId);
    gr.query();
    while (gr.next()) {
        risks.push(gr.sys_id.toString());
    }
    current.u_risks = risks.join(',');
})(current, previous);

 

 

 

Also tried a Client Script: 

vivek_f19_2-1720792776743.png

Code:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
        return;
    }

    // Get the profile value
    var profileSysId = g_form.getValue('u_profile');

    // Display the profile value in a pop-up
    alert('Profile Sys ID: ' + profileSysId);

    // Construct the reference qualifier filter
    var refQualFilter = 'u_profile=' + profileSysId;

    // Display the reference qualifier filter in a pop-up
    alert('Reference Qualifier Filter: ' + refQualFilter);

    // Set the reference qualifier for the u_risks field
    g_form.setValue('u_risks', '');
    g_form.setReadOnly('u_risks', false);
    g_form.getElement('u_risks').setAttribute('data-ref-qual', refQualFilter);
}

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

A reference qualifier is the way to go.  'profile' is the name of the column on the risk table that is a reference to the entity table, and current. refers to the field on the current form/table that is a reference to the profile table so your reference qualifier should instead be

 "profile=" + current.u_entity

following the javascript colon (:) 

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

A reference qualifier is the way to go.  'profile' is the name of the column on the risk table that is a reference to the entity table, and current. refers to the field on the current form/table that is a reference to the profile table so your reference qualifier should instead be

 "profile=" + current.u_entity

following the javascript colon (:) 

vivek_f19
Tera Contributor

Thank you Brad. I very much overcomplicated a simple solution. 

Here is what I came up with that worked as well: 'profile.applies_to=' +current.u_department_organization;