Reference Qualifier

JJose
Tera Expert

I want to restrict the groups displayed in the assignment_group field on the incident form using a reference qualifier. However, I am unable to find the dictionary entry for assignment_group in the incident table. I discovered that the reference table is task, which itself references another table. I believe the base table might be sys_user_group, but I am not certain. Can someone provide guidance on this?

1 ACCEPTED SOLUTION

Many Thanks Sai, It works now.

View solution in original post

11 REPLIES 11

Sorry Gangadhar, is it possible to call a script include in a reference qualifier?, I have tried but its not working, Any tips or ideas will help me, Thanks

Try viewing existing dictionary records where 'Reference qual starts with javascript, Reference qual contains new to see examples.

 

https://<instance_name>.service-now.com/sys_dictionary_list.do?sysparm_query=reference_qualSTARTSWITHjavascript%5Ereference_qualLIKEnew&sysparm_view=advanced 

 

 

Community Alums
Not applicable

Hi @JJose ,

 

Follow the below steps:

 

Do dictionary override on incident table & Add the below code in reference qualifier field:

javascript&colon;'sys_idIN'+new TT().groups(); (Replace TT with your script include name & groups with your function Name)

 

Sai149_0-1716218818912.png

 

You can write the logic in your script include so that it will return comma separated sys id's of the groups.

 

Ex:

groups: function() {
var gr = new GlideRecord('sys_user_group');
gr.addQuery('active', true);
gr.query();
var groups = [];
while (gr.next()) {
groups.push(gr.sys_id.toString());
}
return groups.join(',');
},

 

This worked for me.

 

I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.

I am trying to use the script below to remove 2 groups from the assignment_group on the PDI instance, but it is not working. Can you check what's wrong?

 

function groups() {
    // Create a new GlideRecord object for the 'sys_user_group' table
    var gr = new GlideRecord('sys_user_group');
   
    // Add a query to filter only active groups
    gr.addQuery('active', true);
          gr.addQuery('name', '!=', 'Database');  // Exclude the group with name 'test1'
        gr.addQuery('name', '!=', 'Hardware');  // Exclude the group with name 'test2'
    // Execute the query
    gr.query();
   
    // Initialize an empty array to hold the sys_id values
    var groups = [];
   
    // Iterate over the results
    while (gr.next()) {
        // Add the sys_id of each group to the array
        groups.push(gr.sys_id.toString());
    }
   
    // Return the sys_ids as a comma-separated string
    return groups.join(',');
}

 

Reference Qualifier --> javascript&colon;'sys_idIN'+new TT().groups(); 

Community Alums
Not applicable

Hi @JJose ,

 

The function declaration is the issue i guess.

 

Sai149_0-1716257269041.png

Sai149_1-1716257293336.png

Add the below code in your script include.

 groups: function() {
        var gr = new GlideRecord('sys_user_group');

        // Add a query to filter only active groups
        gr.addQuery('active', true);
        gr.addQuery('name', '!=', 'Database'); // Exclude the group with name 'test1'
        gr.addQuery('name', '!=', 'Hardware'); // Exclude the group with name 'test2'
        // Execute the query
        gr.query();

        // Initialize an empty array to hold the sys_id values
        var groups = [];

        // Iterate over the results
        while (gr.next()) {
            // Add the sys_id of each group to the array
            groups.push(gr.sys_id.toString());
        }

        // Return the sys_ids as a comma-separated string
        return groups.join(',');
    },

 

 In the dictionary override reference qualifier make sure you replace TT with your script include name.

 

Sai149_2-1716257402011.png

 

I tested the code & works for me. Please check & If my answer helped you in any way, please mark it as helpful or correct.