Filter Approvers based on selected RITM

Rocky5
Kilo Sage

Hello All,

 

In the below screenshot, we need to show approvers in 'Select Approver' field based on selected RITM in the 'Select RITM' field. 

Need help on reference qualifier script on 'Select Approver' field so that it shows approvers that belong to the selected RITM.

Rocky5_0-1738631166617.png

 

I tried below but not working.

Rocky5_0-1738632097725.png

 

Any help is appreciated.

 

Thanks,

Rocky.

 

3 REPLIES 3

Amit Verma
Kilo Patron
Kilo Patron

Hi @Rocky5 

 

Change the reference qualifier as below. Please change the variable name as per your Select RITM field. In my case, I have considered Select RITM field internal name as ritm.

javascript:'sysapproval=' + current.variables.ritm;

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Ankur Bawiskar
Tera Patron
Tera Patron

@Rocky5 

you can use this in advanced ref qualifier

Ensure you give correct variable name here

javascript: 'sysapproval=' + current.variables.ritmVariableName + '^ORdocument_id=' + current.variables.ritmVariableName;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Jon Hogland
Tera Guru

@Rocky5 

Hi, I believe your case is better suited for a Client Script rather than a dynamic qualifier. If you'd like to give it a try, create a new Client Script with these properties:

Name: [your_choice]

Table: [sc_req_item]

Type: onChange

Field name: select_ritm_field

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   //Type appropriate comment here, and begin script below

    var itemReference = g_form.getReference('select_ritm_field');  // Get selected Request Item

    if (itemReference) {
        var grApproval = new GlideRecord('sysapproval_approver');
        grApproval.addQuery('sysapproval', itemReference.sys_id);  
        grApproval.orderBy('sys_created_on');  
        grApproval.query();

        if (grApproval.next()) {
            g_form.setValue('select_approver', grApproval.approver.toString()); 
        } else {
            g_form.setValue('select_approver', '');  
        }
    } else {
        g_form.clearValue('select_approver');  // Clear field if no Request Item selected
    }
}

 
I hope this helps. Excited to hear back about your solution, as this was a bit of a learning process for me as well.



If I've at all helped, please return the favor by clicking the thumb next to my post. Thanks!