Execute assignment rule on demand by script

Piero Virgilio
Tera Expert

Hi All,

the client asked me to implement a UI action to suggest an assignment group to the agent after changing some fields of the case (Business Service and other custom fields).

Is there a way to execute on-demand assignment rules, which I have defined to assign the case when it is created, and show the result to the agent who can decide whether or not to accept the suggestion?

I don't want the assignment group of the case always be recalculated on update.

Thanks,
Piero.

1 ACCEPTED SOLUTION

Piero Virgilio
Tera Expert

I've found the solution using GlideFilter.checkRecord() and GlideScopedEvaluator().evaluateScript() functions.

checkRecord allows me to find the assignment rule that match with new values of my record.

evaluateScript returns me the sys_id of the calculated group.

Thanks all for the support,
Piero

View solution in original post

8 REPLIES 8

Piero Virgilio
Tera Expert

I've found the solution using GlideFilter.checkRecord() and GlideScopedEvaluator().evaluateScript() functions.

checkRecord allows me to find the assignment rule that match with new values of my record.

evaluateScript returns me the sys_id of the calculated group.

Thanks all for the support,
Piero

Hi @Piero, Can you please share the details of how you implemented the solution for your use case. Thanks in advance

Hi Shailendra,

this is the code of the Script Incude

var evaluator = new GlideScopedEvaluator();
var ar = new GlideRecord('sysrule_assignment');
ar.addQuery('table', cs.sys_class_name);
ar.orderBy('order');
ar.addActiveQuery();
ar.query();

var matched = false;
while (ar.next() && !matched) {
    matched = GlideFilter.checkRecord(cs, ar.condition);
    if (matched)
        break;
}

var obj = {};

if (ar.group != "") {
    obj.name = ar.group.name.toString();
    obj.id = ar.group.toString();
} else {
    var vars = {
        'current': cs
    };

    var group = new GlideRecord('sys_user_group');
    group.get(evaluator.evaluateScript(ar, 'script', vars));

    obj.name = group.name.toString();
    obj.id = group.sys_id.toString();
}
return JSON.stringify(obj);

cs variable is a Case record (sn_customerservice_case)

Hope this is helpful.

hi there. may i know exactly where did you apply this script? i've been testing it on BR but to no avail