The case is not automatically assigned to a member of the group

srsyam
Tera Contributor

When the assignment group in a case form is changed, the case is not assigned automatically to a member of the changed assignment group. How to resolve this issue

1 ACCEPTED SOLUTION

Omkar Ranjane
Tera Guru

Hi @srsyam,

 

It is not an issue. OOB it works like that.

 

In Case assigned to field shows only those users from selected assignment group which satisfy the condition "roles=sn_esm_agent^ORroles=sn_customerservice.relationship_agent^ORroles=sn_esm_location_agent^ORroles=sn_csm_ocs.ext_agent".

 

Now, if you want to set assigned to value, then it can be achieved by 2 methods.

Check the condition defined on assigned to field, otherwise it will set the user which does not satisfy the condition.

1) If you want to set assigned to field as soon as assignment group changes, then you can create onChange Client Script. 

 

Code Snippet : 

It is not best practice to use glide query in client script, use script include insteed.

You have to create script include and on change client script.

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (newValue != '' & newValue != oldValue) {
        var gr = new GlideAjax('global.AjaxTestScript');
        gr.addParam('sysparm_name', 'getAssignedTo');
        gr.addParam('sysparm_assignmentGroup', g_form.getValue('assignment_group'));
        gr.getXML(democat);
    }

    function democat(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer == "") {
            g_form.addErrorMessage("No Member");
        } else {
            g_form.setValue('assigned_to', answer);
        }
    }
}

Script Include: 

Change encoded query as per query mentioned in case assigned to field. 

var AjaxTestScript = Class.create();
AjaxTestScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getAssignedTo: function() {
		var assignGroup = this.getParameter('sysparm_assignmentGroup');
		var assignTo = "";
		
        var assignMem = new GlideRecord("sys_user_grmember");
        assignMem.addEncodedQuery("group=" + assignGroup + "^user.roles=sn_esm_agent^ORuser.roles=sn_customerservice.relationship_agent^ORuser.roles=sn_esm_location_agent^ORuser.roles=sn_csm_ocs.ext_agent");
        assignMem.query();
        if (assignMem.next()) {
            assignTo = assignMem.user;
        } 
		return assignTo.toString();
    },

    type: 'AjaxTestScript'
});

 

2) If you want to set assigned to field after updating record, then you can create Before Update Business Rule with condition assignment group changes AND assignment group is not empty.

 

Code Snippet :

Change encoded query as per query mentioned in case assigned to field. 

    var assignMem = new GlideRecord("sys_user_grmember");
    assignMem.addEncodedQuery("group=" + current.assignment_group + "^user.roles=sn_esm_agent^ORuser.roles=sn_customerservice.relationship_agent^ORuser.roles=sn_esm_location_agent^ORuser.roles=sn_csm_ocs.ext_agent");
    assignMem.query();
    if (assignMem.next()) {
        current.assigned_to = assignMem.user;
    } else {
        gs.addErrorMessage("No Member in group " + current.assignment_group.getDisplayValue());
        current.setAbortAction(true);
    }

 

If your question is solved, please close the topic by marking my answer "Accept as Solution". This will help others searching for a similar question and will remove the topic from the unsolved list.

View solution in original post

3 REPLIES 3

Hardik2109
Tera Guru

Hi @srsyam ,

On Change Client Scripts execute against a single field, so if you need this to change in the client, you would need to define a separate script for each field. Alternatively, this could be defined to be a Business Rule that executes on Update when (current.assignment_group != previous.assignment_group || current.assigned_to != previous.assigned_to). You will only see the change made after the update completes in this case, though.

Thanks!

newhand
Mega Sage

@srsyam 

Client script with  onChange  may achive this.

When the assigment group changes  set a umember of the group to  "assigned to".

 

 

 

Please mark my answer as correct and helpful based on Impact.

Omkar Ranjane
Tera Guru

Hi @srsyam,

 

It is not an issue. OOB it works like that.

 

In Case assigned to field shows only those users from selected assignment group which satisfy the condition "roles=sn_esm_agent^ORroles=sn_customerservice.relationship_agent^ORroles=sn_esm_location_agent^ORroles=sn_csm_ocs.ext_agent".

 

Now, if you want to set assigned to value, then it can be achieved by 2 methods.

Check the condition defined on assigned to field, otherwise it will set the user which does not satisfy the condition.

1) If you want to set assigned to field as soon as assignment group changes, then you can create onChange Client Script. 

 

Code Snippet : 

It is not best practice to use glide query in client script, use script include insteed.

You have to create script include and on change client script.

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (newValue != '' & newValue != oldValue) {
        var gr = new GlideAjax('global.AjaxTestScript');
        gr.addParam('sysparm_name', 'getAssignedTo');
        gr.addParam('sysparm_assignmentGroup', g_form.getValue('assignment_group'));
        gr.getXML(democat);
    }

    function democat(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer == "") {
            g_form.addErrorMessage("No Member");
        } else {
            g_form.setValue('assigned_to', answer);
        }
    }
}

Script Include: 

Change encoded query as per query mentioned in case assigned to field. 

var AjaxTestScript = Class.create();
AjaxTestScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getAssignedTo: function() {
		var assignGroup = this.getParameter('sysparm_assignmentGroup');
		var assignTo = "";
		
        var assignMem = new GlideRecord("sys_user_grmember");
        assignMem.addEncodedQuery("group=" + assignGroup + "^user.roles=sn_esm_agent^ORuser.roles=sn_customerservice.relationship_agent^ORuser.roles=sn_esm_location_agent^ORuser.roles=sn_csm_ocs.ext_agent");
        assignMem.query();
        if (assignMem.next()) {
            assignTo = assignMem.user;
        } 
		return assignTo.toString();
    },

    type: 'AjaxTestScript'
});

 

2) If you want to set assigned to field after updating record, then you can create Before Update Business Rule with condition assignment group changes AND assignment group is not empty.

 

Code Snippet :

Change encoded query as per query mentioned in case assigned to field. 

    var assignMem = new GlideRecord("sys_user_grmember");
    assignMem.addEncodedQuery("group=" + current.assignment_group + "^user.roles=sn_esm_agent^ORuser.roles=sn_customerservice.relationship_agent^ORuser.roles=sn_esm_location_agent^ORuser.roles=sn_csm_ocs.ext_agent");
    assignMem.query();
    if (assignMem.next()) {
        current.assigned_to = assignMem.user;
    } else {
        gs.addErrorMessage("No Member in group " + current.assignment_group.getDisplayValue());
        current.setAbortAction(true);
    }

 

If your question is solved, please close the topic by marking my answer "Accept as Solution". This will help others searching for a similar question and will remove the topic from the unsolved list.