- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2017 09:28 AM
I think I am close. I want to prevent a user from using an (inactive) value/name in the group. (Normally being pulled from their templates). Here is my script:
var gr = new GlideQuery('groups');
gr.addQuery('name',current.assignment_group.getDisplayValue());
gr.addQuery('active');
gr.query();
if (gr.active == false) {
gs.addInfoMessage('This group is not active, please update your template accordingly');
current.assignment_group.setError('This group is not active, please update your template accordingly');
current.setAbortAction(true);
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2017 02:41 PM
My bad. I found the error. It was line no 1
Here is the updated code.
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id',current.assignment_group);
gr.addQuery('active', true);
gr.query();
if(!gr.next()) {
gs.addInfoMessage('This group is not active, please update your template accordingly');
current.assignment_group.setError('This group is not active, please update your template accordingly');
current.setAbortAction(true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2017 09:31 AM
Hello Corey,
GlideQuery should be replaced with GlideRecord. Can you please give more details on what you mean by "I want to prevent a user from using an (inactive) value/name in the group"
No need to use GlideRecord if this check is for the same table. Complete script should be
if (current.active == false) {
gs.addInfoMessage('This group is not active, please update your template accordingly');
current.assignment_group.setError('This group is not active, please update your template accordingly');
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2017 09:36 AM
In the groups table, for example a group is no longer active (i.e Active = False). The group is still being applied on the person change form via their template. On before save, I want the user to be prompted that he/she cannot use group and to use an Active one.
User applies their template, template still has an old group (that is no longer active). I need the script to lookup the groups table based on users selection and confirm if 'that' group is active or not.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2017 10:06 AM
Pradeep - The business rule that I have applying this script is on the change form. - before insert.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2017 11:20 AM
Hello Corey,
Thanks for the update. Please create a BEFORE business rule on change table with below script.
var gr = new GlideQuery('sys_user_group');
gr.addQuery('sys_id',current.assignment_group);
gr.addQuery('active', true);
gr.query();
if(!gr.next()) {
gs.addInfoMessage('This group is not active, please update your template accordingly');
current.assignment_group.setError('This group is not active, please update your template accordingly');
current.setAbortAction(true);
}