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.

Slush bucket values based on assignment group

prashant8
Tera Expert

Hi everyone , thanks in advance .

When we change assignment group , show all group members in watch list (list collector type field).

Please provide suggestion 

@Ankur Bawiskar 

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please use the below script:-

 

1) Write the below onchange client script of field assignment group:-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    
        var ga = new GlideAjax('GetGrpmembers');
        ga.addParam('sysparm_name', 'GetGrp');
        ga.addParam('sysparm_group_name', g_form.getValue('assignment_group'));
        ga.getXML(HelloWorldParse);

        function HelloWorldParse(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            var fields = [];
            fields = JSON.parse(answer);
            for (i = 0; i < fields.length; i++) {
                g_form.setValue("watch_list", fields[i]);

            }
        }
    }

 

Then write a script include with the below script:-

 

var GetGrpmembers = Class.create();
var arr = [];
GetGrpmembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	GetGrp: function() {
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('group', this.getParameter('sysparm_group_name'));
        gr.query();
        while (gr.next()) {
            arr.push(gr.user.toString());
        }
		var setMembers = JSON.stringify(arr);
        return setMembers;
	},
    type: 'GetGrpmembers'
});

 

Now once you have both the script as soon as you select assignment group all the members will be populated on watchlist .

 

Please mark my answer correct/helpful based on Impact.

View solution in original post

11 REPLIES 11

no just copy pasted your client and script include code , it throws that error 

Where is it throwing the error? On my instance it is not throwing any such error. Can you paste some screenshots? Also I see some other threads  on similar issue:-

 

https://www.servicenow.com/community/now-platform-forum/unable-to-find-ui-action-with-name-undefined...