Auto populate assignment groups for requested for user

Dileep2
Tera Contributor

Hello Everyone, 

 

I want to populate all the assignment groups of user belong to in the catalog item. 
variable - requested for - Sys user table 

assignment groups - list collector - Sys user group table. 
with logged in user I have got by using reference qualifier. Can anyone help me with the solution if I change requested for how can I get the list of assignment groups user is part of.

 

Thank you !! Your help is much appreciated!!

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage
Giga Sage

Hi @Dileep2 ,

 

You can achieve this via OnChange Client script and script include ,

 

Key Point : 

1. assignment groups - list collector - sys_user_grmember table. (make it read only so that no can change it)

2. Create client callable si

3. Please change the backend name according to your requirement

 

OnChange:

 

 

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

    var sysId = g_form.getValue('requested_for');
    var ga = new GlideAjax('getRequestedForDetail');
    ga.addParam('sysparm_name', 'getGroupDetail');
    ga.addParam('sysparm_id', sysId);
    ga.getXML(getResponse);

}

function getResponse(response) {
    var ans = response.responseXML.documentElement.getAttribute('answer');
 
        g_form.setValue('requested_for_assignment_group', ans);
    

    }
}

 

 

 

swathisarang98_0-1710183049718.png

Script Include:

swathisarang98_1-1710183070972.png

 

 

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

    getGroupDetail: function() {
		var sysID = this.getParameter('sysparm_id');
		var gr = new GlideRecord('sys_user_grmember');
	
		gr.addQuery('user',sysID);
		gr.query();
        var arr = [];
        while (gr.next()) {
            arr.push(gr.group.name.toString());
			
        }
        // gs.info('line number 15 ' + arr);
        return  arr.toString();



    },


    type: 'getRequestedForDetail'
});

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

8 REPLIES 8

Hello Swathi, 

Found one issue.

Assignment groups are getting populated but after submitting the request, in the RITM the assignment group field is becoming empty. The field is getting cleared. 

Could you please have a look into it

Hi @Dileep2 , you can make Applies on Requested item and applies on catalog task true in client script

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Hello Swathi

Sorry its not working 

@Dileep2 could you please share the screen shot of the issue ?