Find assigned to is member of particular group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 04:37 AM
Hi All,
I have assigned to field referencing to user table. Now I want to check if the Assigned to user is part of "BCKAM -200&210" group. If Yes I have to clear Assignment group field value.
Please suggest any solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 12:51 AM
Hi @Dileep2
Follow below for your scripts
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var assignedTo = g_form.getValue("assigned_to");
var ga = new GlideAjax('scriptIncludeName');
ga.addParam('sysparm_name', 'functionName');
ga.addParam('sysparm_assignedTo', assignedTo );
ga.getXML(callback);
}
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
in the script include
var scriptIncludeName= Class.create();
scriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
functionName: function () {
var assignedTo= this.getParameter('sysparm_assignedTo');
var groupSysId = "abcd";//this should be sys_id of BKACS group
var member = new GlideRecord("sys_gr_member");
member.addQuery("group",groupSysId);
member.addQuery("user",assignedTo);
member.query();
if(member.next()){
return true; //It means he is part of it
}
}
}
})
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 01:10 AM
What you have tried?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 01:18 AM
Hi @Dileep2 ,
Please find below script to resolve your issue:
Onchange client script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var usr=g_form.getValue("assigned_to");
var ga = new GlideAjax('validateAssignee');
ga.addParam('sysparm_name', 'getCampus');
ga.addParam('sysparm_userid',usr);
ga.getXML(updateCampus);
function updateCampus(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer=='true') {
g_form.setValue("assigned_to", '');
g_form.addErrorMessage('Assignee is member of XYZ group');
}
}
}
Client Callable script include (Replace 'ITSM App-Dev' with your group name):
var validateAssignee = Class.create();
validateAssignee.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCampus: function() {
var userid = this.getParameter('sysparm_userid');
var usr = new GlideRecord('sys_user_grmember');
usr.addEncodedQuery('group.name=ITSM App-Dev^user=' + userid); // Replace 'ITSM App-Dev' with your group name
usr.query();
if (usr.hasNext()) {
return 'true';
} else {
return 'false';
}
},
type: 'validateAssignee'
});
Regards, Shekhar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 01:35 AM
It should be pretty simple.
What script did you start with and where are you stuck?
If you try from your side it will be learning for you as well.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader