Advanced Reference Qualifier for a Reference Field on a UI Page Modal Popup

triciav
Kilo Sage

I am struggling with how to add an advanced reference qualifier for the UI Action "Assess" on the sn_risk_risk table.

When you click Assess it loads a UI Page Modal with a Popup to Select the Assessor and Approver.

I need to set a reference qualifier or filter on the Assessor  so that only the users that are in the same department as the Risk Owners Department are listed.

If someone can assist please with some direction on how to achieve this.

This is for Risk and creating a risk assessment. [GRC]

triciav_0-1739993823055.png

 

https://PDIInstancename.service-now.com/nav_to.do?uri=sys_ui_action.do?sys_id=9859522b77073010c4a4b0...

1 ACCEPTED SOLUTION

Hello, 

 

first I have to mention best practice to customizing out-of-box records is to make a copy and deactivate OOB record. So here are steps according to the best practice:

 

Customizing UI Action

1. Open UI Action 'Assess' (Sys ID: 9859522b77073010c4a4b0bdbd5a9916)

2. Make a copy: Open additional action menu and click on 'Insert and Stay', it will open new record

3. Delete all code in Script field, paste this one:

 

function showAssessorApproverModal() {
    //Check if there is an assessment in draft state created from scope
    if (!g_scratchpad.draftAsmt) {
        (function() {
            g_form.getReference('owner', openModal);
        })();

        function openModal(owner) {
            var ownerDepartment = owner.getValue('department');

            var modal = new GlideModal('sn_risk_advanced_assign_assessor_approver_risk_custom');
            modal.setTitle(getMessage('Add Assessor and Approver'));
            modal.setPreference("department", ownerDepartment);
            modal.setBackdropStatic(true);
            modal.render();
        }
    } else {
        gsftSubmit(null, g_form.getFormElement(), 'risk_assess_adv');
    }
}


if (typeof window == 'undefined') {
    var count = new sn_risk_advanced.RiskAssessmentUtils().markAssess(new sn_risk_advanced.RiskUtilities().checkIfAsmtInDraft(current));
    if (count == 1) {
        gs.addInfoMessage(gs.getMessage("The assessment is successfully initiated. The assessors and approvers for this assessment are as specified in the risk assessment scope."));
    }
    action.setRedirectURL(current);
}

 

4. Save it

5. Open OOB UI Action (Sys ID: 9859522b77073010c4a4b0bdbd5a9916)

6. Set checkbox 'Active' to false (unchecked)

 

Customizing UI Page

1. Open UI Page 'assign_assessor_approver_risk' (Sys ID: a74d56eb77073010c4a4b0bdbd5a9990)

2. Make a copy: Open additional action menu and click on 'Insert and Stay', it will open new record

3. Change value in field 'Name' to assign_assessor_approver_risk_custom

4. Delete all code in HTML field, paste this one:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <g:evaluate>
        var department = RP.getWindowProperties().department || RP.getParameterValue('department');
        var newAssessorRefQual = 'roles=sn_risk_advanced.ara_assessor^department=' +
        department +'^active=true^EQ';
    </g:evaluate>
    <style>
        #assign_assessor_approver .required-marker {
            display: inline-block;
        }
    </style>
    <div class="row">
        <div class="form-horizontal" id="assign_assessor_approver">
            <div class="form-group">
                <label id="assessor_label" class="col-sm-3 col-sm-offset-1 control-label"><span id="assessor_span" mandatory="true" class="required-marker"></span>${gs.getMessage('Assessor')}</label>
                <div class="col-sm-6" aria-label="assessor">
                    <g:ui_reference name="assessor" id="assessor" table="sys_user" field="name" query="${newAssessorRefQual}" onchange="checkMandatoryFields(this)" />
                </div>
            </div>
            <div class="form-group">
                <label id="approver_label" class="col-sm-3 col-sm-offset-1 control-label"><span id="approver_span"></span>${gs.getMessage('Approver')}</label>
                <div class="col-sm-6" aria-label="approver">
                    <g:ui_reference name="approver" id="approver" table="sys_user" field="name" query="roles=sn_risk_advanced.ara_approver^active=true^EQ" />
                </div>
            </div>
            <div class="form-group">
                <label id="days_label" class="col-sm-3 col-sm-offset-1 control-label"><span id="days_span" mandatory="true" class="required-marker"></span>${gs.getMessage('Days to overdue')}</label>
                <div class="col-sm-6">
                    <input aria-label="Days to overdue" id="days" name="days" type="number" min="1" value="5" class="form-control" onchange="enableSubmitButton()"></input>
                </div>
            </div>
            <div class="modal-footer">
                <div class="row">
                    <div class="col-sm-6 clearfix pull-right">
                        <button class="btn btn-default" onclick="handleCancel()">${gs.getMessage('Cancel')}</button>
                        <button id="submit" class="btn btn-primary disabled" tabindex="-1" aria-disabled="false" onclick="handleSubmit()">${gs.getMessage('Submit')}</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</j:jelly>

 

It should work as required, only users with the same value 'Department' as has a user selected in 'Owner' field.

 

If my answer helped you, please mark it as correct and helpful, thank you 👍
Martin

View solution in original post

10 REPLIES 10

Martin Friedel
Mega Sage

Hello,

 

I installed GRC module on my PDI, but still I am not able to find that UI Page.

Could you share HTML, Client Script and Processing script so I can copy the UI Page and look how it can be customized per your requirement?

 

Martin

 

Hi Martin,

Did you install the Advanced Risk IRM?

Hello triciav,

 

thank you for helpful suggestion. I have checked UI Action, it calls UI Page 'assign_assessor_approver_risk':

  • Sys ID: a74d56eb77073010c4a4b0bdbd5a9990
  • link: ...service-now.com/sys_ui_page.do?sys_id=a74d56eb77073010c4a4b0bdbd5a9990

 

Check HTML on row 13, there is the encoded query you looking for:

 

refqual.JPG

 

Will you be able to modify it yourself or do you need help with that? Getting Owner's department needs scripting and customizing.

 

If my answer helped you, please mark it as correct and helpful, thank you 👍
Martin

Hi Martin, YES please I need help with scripting that. I am not too good at Jelly and UI Page scripting.

That would be awesome if you have the skills to help.

Thank you sooooo much!