Populate Assignment group value based on other field

Suzy
Tera Contributor

Hi All, 

 

I have a field name called Support group in cmdb_ci table and that field value needs to be populated in Assignment group in change_request table if I select Configuration item in change_request table in ServiceNow. Business rule before Insert and update to be created

 

(function executeRule(current, gsr) {

    // Check if CI is set

    if (current.cmdb_ci) {

        var ciGR = new GlideRecord('cmdb_ci');

        if (ciGR.get(current.cmdb_ci)) {

            // If CI has a support group, use it

            if (ciGR.support_group) {

                current.assignment_group = ciGR.support_group;

                return;

            }

        }

    }

})(current, gsr);

 

The above code is not working for me, kindly suggest. 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Suzy 

you can simply dot walk and set and no GlideRecord needed

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

    // Add your code here
    current.assignment_group = current.cmdb_ci.support_group;

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Suzy 

you can simply dot walk and set and no GlideRecord needed

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

    // Add your code here
    current.assignment_group = current.cmdb_ci.support_group;

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Suzy
Tera Contributor

Thank you, it worked!!