Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to populate Assignment group in RITM?

User205031
Tera Contributor

Hi All,

 

There is a variable 'support group' which is a select box type with group names and I want to populate assignment group in RITM with the support group selected. How to achieve since Assignment group is a reference field and Support group is a select box field. Support group variable value is being send from 3rd party.

 

I have written a client script & script include but its not populating:

 

Client Script:

 

function onLoad() {
   
    var a = g_form.getValue('support_group');
    alert(a);

    var ga = new GlideAjax('SupportGroupHandler');
    ga.addParam('sysparm_name', 'getAssignmentGroup');
    ga.addParam('sysparm_group', g_form.getValue('support_group'));
    ga.getXMLAnswer(response);
       
        function response(serverResponse) {
            var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
             alert('Line 12' +answer);
           
                g_form.setValue('assignment_group', answer); // sys_id returned from Script Include
        }
        //return;
        //Type appropriate comment here, and begin script below

    }
 
Script Include :
var SupportGroupHandler = Class.create();
SupportGroupHandler.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getAssignmentGroup: function() {
        gs.log('hiline6');
        var supportGroup = this.getParameter('sysparm_group');
        gs.log('hiline10' + supportGroup);
        var groupSysId = '';

        var a = new GlideRecord('sys_user_group');
        a.addQuery('name', supportGroup);
        a.query();
        if (a.next()) {
            groupSysId = gr.getUniqueValue();

        }
        return groupSysId;
    },

    type: 'SupportGroupHandler'
});
 
Value is not populating in Assignment group.
 
Is anything wrong with the script?
1 ACCEPTED SOLUTION

Hi @User205031 ,

  • Trigger: Service Catalog (or Record Created: sc_req_item).

  • Action 1: Get Catalog Variables

    • Get the variables for the Submitted Request (RITM).

    • Select your Support Group variable.

  • Action 2: Look Up Record

    • Table: Group [sys_user_group]

    • Conditions: Name is [Trigger > RITM > Variables > Support Group]

    • Note: This action searches the Group table for a group where the name matches your variable string.

  • Logic: If (Safety Check)

    • Condition: [2. Look Up Record > Group Record] is not empty.

  • Action 3: Update Record (Inside the "If" block)

    • Record: [Trigger > Requested Item Record]

    • Fields: Assignment Group = [2. Look Up Record > Group Record]

 

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma

 

 

View solution in original post

12 REPLIES 12

Nawal Singh
Tera Guru

Hi @User205031 ,

Please use below code- 

Script include- 

 

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

    getAssignmentGroup: function() {
        var supportGroup = this.getParameter('sysparm_group');
        gs.log('SupportGroupHandler - Incoming group: ' + supportGroup);

        var groupSysId = '';
        var gr = new GlideRecord('sys_user_group');
        gr.addQuery('name', supportGroup);
        gr.query();

        if (gr.next()) {
            groupSysId = gr.getUniqueValue();  // <-- FIXED
        }

        return groupSysId;
    },

    type: 'SupportGroupHandler'
});

 

and Client script- 

 

function onLoad() {

    var supportGroup = g_form.getValue('support_group');
    if (!supportGroup) return;

    var ga = new GlideAjax('SupportGroupHandler');
    ga.addParam('sysparm_name', 'getAssignmentGroup');
    ga.addParam('sysparm_group', supportGroup);

    ga.getXMLAnswer(function(response) {
        if (response) {
            g_form.setValue('assignment_group', response);
        } else {
            console.log("No sys_id returned for support group: " + supportGroup);
        }
    });
}

 

If you found my response helpful, please mark it as helpful and accept it as the solution.

Thank you
Nawal Singh

ursnani
Giga Guru

HI

 

IN the Flow or Workflow you can read the variable value and set the value of Support group to Assignment group value

Hi @ursnani ,

 

I was trying to do that but cant since Assignment group is a reference field and support group is a choice field. Not able to select support group for Assignment group.

 

User205031_1-1763358620433.png

 

Bhavya11
Kilo Patron
Kilo Patron

Hi @User205031 ,

 

you have wrongly fetched the information

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

    getAssignmentGroup: function() {
        gs.log('hiline6');
        var supportGroup = this.getParameter('sysparm_group');
        gs.log('hiline10' + supportGroup);
        var groupSysId = '';

        var a = new GlideRecord('sys_user_group');
        a.addQuery('name', supportGroup);
        a.query();
        if (a.next()) {
            groupSysId = a.getUniqueValue();//use a.getUniqueValue instead of gr.getUniqueValue

        }
        return groupSysId;
    },

    type: 'SupportGroupHandler'
});

client script:

function onLoad() {
var a = g_form.getValue('support_group');
    alert(a);

    var ga = new GlideAjax('SupportGroupHandler');
    ga.addParam('sysparm_name', 'getAssignmentGroup');
    ga.addParam('sysparm_group', g_form.getValue('support_group'));
   ga.getXMLAnswer(function(response){
	if(response){
		  alert('Line 12' +response);
		 g_form.setValue('assignment_group', response); // sys_id returned from Script Include
	}

   });
}