Hiding a particular group in assigment group filed in incident form

keerthana219
Kilo Contributor

how to hide a particular in group in assignment field in incident form, even when any group member tries to fill in assigned to field, the group shouldn't populate in assignment group field

2 REPLIES 2

AnkaRaoB
Giga Guru

Hi @keerthana219 ,

 

If you want to prevent a specific group from being populated in the “Assignment Group” field, even when a member of that group is selected in the “Assigned To” field, you can achieve this by using Client Scripts + Business Rules.

Create an onChange Client Script on the Incident table for the Assigned To field.

Purpose:

Detect the selected user

Check their group

Clear Assignment Group if it is restricted

Script Example:

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || !newValue) {

        return;

    }

    var ga = new GlideAjax('CheckUserGroup');

    ga.addParam('sysparm_name', 'isUserInRestrictedGroup');

    ga.addParam('sysparm_user', newValue);

    ga.getXMLAnswer(function(response) {

        if (response == 'true') {

            g_form.clearValue('assignment_group');

            g_form.showFieldMsg('assignment_group',

                'This group is restricted and cannot be auto-assigned.',

                'error');

        }

    });

}

 Step 2: Script Include (Client Callable)

Create a Script Include to check whether the user belongs to the restricted group.

Make sure:

 “Client Callable” is checked

Script Example:

var CheckUserGroup = Class.create();

CheckUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    isUserInRestrictedGroup: function () {

        var userId = this.getParameter('sysparm_user');

        var restrictedGroup = 'RESTRICTED_GROUP_SYS_ID'; // Replace with actual sys_id

        var gr = new GlideRecord('sys_user_grmember');

        gr.addQuery('user', userId);

        gr.addQuery('group', restrictedGroup);

        gr.query();

        return gr.hasNext();

    }

});

 Replace RESTRICTED_GROUP_SYS_ID with the actual sys_id of the group.

 Step 3: Business Rule (Before Insert/Update)

Client Scripts only work in UI.

To prevent assignment through API, imports, or scripts, add a Business Rule.

Business Rule Setup:

Table: Incident

When: Before

Insert & Update: Checked

Script Example:

(function executeRule(current, previous) {

 

    if (!current.assigned_to) {

        return;

    }

    var restrictedGroup = 'RESTRICTED_GROUP_SYS_ID';

    var gr = new GlideRecord('sys_user_grmember');

    gr.addQuery('user', current.assigned_to);

    gr.addQuery('group', restrictedGroup);

    gr.query();

    if (gr.hasNext()) {

        current.assignment_group = '';

        gs.addErrorMessage('Restricted group cannot be assigned automatically.');

        current.setAbortAction(true);

    }

})(current, previous);

If this answer resolved your question, please mark it as solved to help others in the community.

Tejas Adhalrao
Tera Guru

Hi @keerthana219  ,

 

1) click on assignment group  field  , open configure dictionary

TejasAdhalrao_0-1770688033070.png

 

2) add the filter condition 

TejasAdhalrao_1-1770688111623.png

aslo you can add this condition

TejasAdhalrao_2-1770688135462.png

 

 

 If you found my solution helpful, please mark it as Helpful or Accepted Solution...!

thanks,

tejas

Email: adhalraotejas1018@gmail.com

LinkedIn: https://www.linkedin.com/in/tejas1018