- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2023 12:52 PM - edited ‎02-22-2023 12:58 PM
So the goal is to permit only group members to "assigned to" tasks among themselves and not the customer. For instance, when a group is assigned and if a user is not part of the assignment group, they get read-only field for "Assigned to", when the user who access the form is part of the group they get the choice to pick the group member. Please help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2023 08:18 AM
Ok. I am answering my own question. I tried dark megic and it worked.
This is script include:
var UserInfo4 = Class.create();
UserInfo4.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isUserInGroup: function() {
var user_id = this.getParameter('sysparm_user_id');
var group_id = this.getParameter('sysparam_group_id');
var grUser = new GlideRecord('sys_user_grmember');
grUser.addQuery('user', user_id);
grUser.addQuery('group', group_id);
grUser.query();
if (grUser.next()) {
return "true";
}
return 'false';
},
type: 'UserInfo4'
});
This is OnChange client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var user_id = g_user.userID;
var ajax = new GlideAjax('UserInfo4');
ajax.addParam('sysparm_name', 'isUserInGroup');
ajax.addParam('sysparm_user_id', user_id);
ajax.addParam('sysparam_group_id', newValue);
ajax.getXML(setisUserInGroup);
function setisUserInGroup(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
//alert(answer);
if(answer == "true"){g_form.setReadOnly('assigned_to', false);}else{g_form.setReadOnly('assigned_to', true);
}
}
}
This is onLoad:
function onLoad() {
//Type appropriate comment here, and begin script below
//alert(g_scratchpad.grp);
var user_id = g_user.userID;
var group_id = g_form.getValue('assignment_group')
var ajax = new GlideAjax('UserInfo4');
ajax.addParam('sysparm_name', 'isUserInGroup');
ajax.addParam('sysparm_user_id', user_id);
ajax.addParam('sysparam_group_id', group_id);
ajax.getXML(setisUserInGroup);
function setisUserInGroup(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
//alert(answer);
if(answer == "true"){g_form.setReadOnly('assigned_to', false);}else{g_form.setReadOnly('assigned_to', true);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2023 01:07 PM
I see two ways to go about this
1 - Add an ACL to the assigned to field for the table that uses a script and checks if they are a member of the group and if not then return false so the field is read only.
2 - User a onLoad client script to make a client GlideRecord/REST API call to check the sys_user_grmember table to see if the current user is in the group and if not make the field read-only.
I would suggest option 1, it will be easier and will prevent the person from using the list to change the assigned to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2023 01:08 PM
Hi,
You need to write a onLoad client script for this with a GlideAjax (to check if user is a part of assignment group or not).
GlideAjax | ServiceNow Developers
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2023 05:58 AM
GlideAjax is a dark magic to me. Would you mind pointing me how could I achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2023 08:18 AM
Ok. I am answering my own question. I tried dark megic and it worked.
This is script include:
var UserInfo4 = Class.create();
UserInfo4.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isUserInGroup: function() {
var user_id = this.getParameter('sysparm_user_id');
var group_id = this.getParameter('sysparam_group_id');
var grUser = new GlideRecord('sys_user_grmember');
grUser.addQuery('user', user_id);
grUser.addQuery('group', group_id);
grUser.query();
if (grUser.next()) {
return "true";
}
return 'false';
},
type: 'UserInfo4'
});
This is OnChange client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var user_id = g_user.userID;
var ajax = new GlideAjax('UserInfo4');
ajax.addParam('sysparm_name', 'isUserInGroup');
ajax.addParam('sysparm_user_id', user_id);
ajax.addParam('sysparam_group_id', newValue);
ajax.getXML(setisUserInGroup);
function setisUserInGroup(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
//alert(answer);
if(answer == "true"){g_form.setReadOnly('assigned_to', false);}else{g_form.setReadOnly('assigned_to', true);
}
}
}
This is onLoad:
function onLoad() {
//Type appropriate comment here, and begin script below
//alert(g_scratchpad.grp);
var user_id = g_user.userID;
var group_id = g_form.getValue('assignment_group')
var ajax = new GlideAjax('UserInfo4');
ajax.addParam('sysparm_name', 'isUserInGroup');
ajax.addParam('sysparm_user_id', user_id);
ajax.addParam('sysparam_group_id', group_id);
ajax.getXML(setisUserInGroup);
function setisUserInGroup(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
//alert(answer);
if(answer == "true"){g_form.setReadOnly('assigned_to', false);}else{g_form.setReadOnly('assigned_to', true);
}
}
}