Assignment rules to execute on change of fields. in the form

Mahesh137
Tera Contributor

Hi all,

Can anyone help here?

I got a requirement. where on the change of fields in the form (assignment group and business services of the xyz table) the assignment rule should execute 

 

 

2 REPLIES 2

newhand
Mega Sage

@Mahesh137 
From the document,if the task has be assgned , assignment rules will not run.

However ,you can  use BR or Data lookup rules to achive your requirement.
link: data lookup 

 

 

 

 

 

The Assignment rules module allows you to automatically set a value in the assigned_to and assignment_group fields when a set of conditions occurs.

An assignment rule must also meet these additional criteria to run:
  • The task record has been created or updated. Assignment rules do not apply to unsaved changes on a form.
  • The task record must be unassigned. The record cannot have an existing value for either the assigned_to or assignment_group fields. Assignment rules cannot overwrite existing assignments (including assignments set by a default value or a previously run assignment rule).
  • The assignment rule is the first rule that matches the table and conditions. If more than one assignment rule matches the conditions, only the rule with the lowest order value runs.
Please mark my answer as correct and helpful based on Impact.

Sandeep Rajput
Tera Patron
Tera Patron

@Mahesh137 You can create an onBefore Update business rule on your table as follows.

 

Screenshot 2023-11-20 at 9.06.30 AM.pngScreenshot 2023-11-20 at 9.07.01 AM.png

Here is the script

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var evaluator = new GlideScopedEvaluator();
    var ar = new GlideRecord('sysrule_assignment');
    ar.addQuery('table', current.sys_class_name);
    ar.orderBy('order');
    ar.addActiveQuery();
    ar.query();

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

    if (ar.group != "") {        
        current.assignment_group = ar.group.toString();
    } else {
        var vars = {
            'current': current
        };

        var group = new GlideRecord('sys_user_group');
        group.get(evaluator.evaluateScript(ar, 'script', vars));
         
        current.assignment_group = group.sys_id.toString();
    }

})(current, previous);

 

Source: https://www.servicenow.com/community/csm-forum/execute-assignment-rule-on-demand-by-script/m-p/40234...