Populate Assigned to field on the basis of caller id user

anuragnegi4
Tera Contributor

i need to populate only those users in the "assigned to" field belongs to the selected "assignment group" that have same country of "caller id" field  in incident form how can i do that ? 

1 ACCEPTED SOLUTION

yashkamde
Tera Contributor

You can create one script include for filyering out the records on basic of your condition and then use that script include in reference qualifier advanced one then it will work,

Script Include Code ->
Screenshot 2025-11-25 144012.png
Reference Qualifier configuration ->

 

Screenshot 2025-11-25 144026.png


Result ->
abc.png

If you find this helpful plz mark as helpful...

View solution in original post

2 REPLIES 2

Vishal_Jaiswal
Mega Guru

Hi @anuragnegi4 ,

Please try the steps below:

 

Step 1: Create the Script Include
Name: IncidentAssignmentFilter
Client callable: Checked
Script: Paste the following code:

var IncidentAssignmentFilter = Class.create();
IncidentAssignmentFilter.prototype = {
    initialize: function() {},

    filterByGroupAndCountry: function(assignmentGroup, callerId) {
        var userList = [];

        // 1. If no group is selected, return nothing (or all users, depending on preference)
        if (gs.nil(assignmentGroup)) {
            return 'sys_id=-1'; 
        }

        // 2. Get the Caller's Country
        var callerCountry = '';
        if (!gs.nil(callerId)) {
            var grCaller = new GlideRecord('sys_user');
            if (grCaller.get(callerId)) {
                callerCountry = grCaller.getValue('country');
            }
        }

        // 3. Query the Group Member table
        var grMember = new GlideRecord('sys_user_grmember');
        grMember.addQuery('group', assignmentGroup);
        
        // 4. If we found a caller country, add it to the query via dot-walking
        if (callerCountry) {
            grMember.addQuery('user.country', callerCountry);
        }
        
        grMember.query();

        while (grMember.next()) {
            userList.push(grMember.getValue('user'));
        }

        // 5. Return the query string
        if (userList.length > 0) {
            return 'sys_idIN' + userList.join(',');
        } else {
            return 'sys_id=-1'; // No users matched
        }
    },

    type: 'IncidentAssignmentFilter'
};

 

Step 2: Configure the 'Assigned to' Dictionary
Open an Incident form.
Right-click on the Assigned to label and select Configure Dictionary.
Scroll down to the Reference Specification tab
Use Reference Qualifier: Advanced.
Reference qual: Paste the following line: javascript:new IncidentAssignmentFilter().filterByGroupAndCountry(current.assignment_group, current.caller_id)

Step 3: Add Dictionary Attributes
For the filter to update immediately when you change the "Caller" or "Assignment Group" on the form (without saving), you must tell the system to watch those fields.
On the same Dictionary Entry form (from Step 2), click Advanced View (if not already visible).
Find the Attributes field.
Add the following attribute to the existing list (comma-separated): ref_qual_elements=assignment_group;caller_id
Example of how the whole field might look: edge_encryption_enabled=true,ref_qual_elements=assignment_group;caller_id
Click Update.

 

 

Regards,

Vishal

yashkamde
Tera Contributor

You can create one script include for filyering out the records on basic of your condition and then use that script include in reference qualifier advanced one then it will work,

Script Include Code ->
Screenshot 2025-11-25 144012.png
Reference Qualifier configuration ->

 

Screenshot 2025-11-25 144026.png


Result ->
abc.png

If you find this helpful plz mark as helpful...