autopopulate assignment group member into the watchlist

edwardwong
Tera Contributor

I need to auto populate the watchlist with the assignment group that have been selected on an incident form and it change in real time. so if it in hard the watchlist will have all the group member, when it in software, the watchlist should be change to the software group member, when it blank the watchlist should also be blank. How do i get a group on the watchlist when you can only pick on the user table?

1 ACCEPTED SOLUTION

Hi @edwardwong ,

In that case use below client script and script include:-

Client Script Onchange of assignment group:-

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    //Populate Support group from Service Offering
	g_form.setValue('watch_list','');
    var assignmentGroup = new GlideAjax('getUsersWatchList'); //test is script include
    assignmentGroup.addParam('sysparm_name', 'getWatchList');
    assignmentGroup.addParam('sysparm_group', newValue);
    assignmentGroup.getXML(setWatchList);

    function setWatchList(response) {
        var group = response.responseXML.documentElement.getAttribute('answer');
	
		g_form.setValue('watch_list',group);

    }

}

 

Script include Client Callable :-

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

    getWatchList: function() {
        var grArr = [];
        var assignmentGroup = this.getParameter('sysparm_group');
        var grpMembers = new GlideRecord("sys_user_grmember");
        grpMembers.addQuery("group", assignmentGroup);
        grpMembers.query();
        while (grpMembers.next()) {
            grArr.push(grpMembers.getValue('user'));
        }
       return grArr.toString();
    },

    type: 'getUsersWatchList'
});

 

GunjanKiratkar_0-1670836304883.png

GunjanKiratkar_1-1670836338295.png

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

9 REPLIES 9

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @edwardwong 

Create After Update/ insert BR

Condition: assignment group changes

Script 

 

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

    // Add your code here
    current.watch_list = "";

    var grpMembers = new GlideRecord("sys_user_grmember");
    grpMembers.addQuery("group", current.assignment_group);

    grpMembers.query();

    while (grpMembers.next()) {

        var user = (',' + grpMembers.user);

        current.watch_list += user;

    }

})(current, previous);

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

It didnt work, are you sure we dont need to use glideajax and script include to have the change in real time 

Hi @edwardwong ,

In that case use below client script and script include:-

Client Script Onchange of assignment group:-

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    //Populate Support group from Service Offering
	g_form.setValue('watch_list','');
    var assignmentGroup = new GlideAjax('getUsersWatchList'); //test is script include
    assignmentGroup.addParam('sysparm_name', 'getWatchList');
    assignmentGroup.addParam('sysparm_group', newValue);
    assignmentGroup.getXML(setWatchList);

    function setWatchList(response) {
        var group = response.responseXML.documentElement.getAttribute('answer');
	
		g_form.setValue('watch_list',group);

    }

}

 

Script include Client Callable :-

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

    getWatchList: function() {
        var grArr = [];
        var assignmentGroup = this.getParameter('sysparm_group');
        var grpMembers = new GlideRecord("sys_user_grmember");
        grpMembers.addQuery("group", assignmentGroup);
        grpMembers.query();
        while (grpMembers.next()) {
            grArr.push(grpMembers.getValue('user'));
        }
       return grArr.toString();
    },

    type: 'getUsersWatchList'
});

 

GunjanKiratkar_0-1670836304883.png

GunjanKiratkar_1-1670836338295.png

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi @edwardwong ,

Please mark my response as correct if it resolves your query.

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy