- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 12:18 PM
Hello, I'm creating a catalog for creating groups, but I would like to check if the name of the group that is being requested already exists, I created a script but on the client I can't use "current.variables" I would like some help.
here is my script
var gr = new GlideRecord("sys_user_group");
gr.addQuery("name",group);
gr.query();
if(!gr.next()){
//Group not available..
gr.initialize();
gr.name=group;
gr.insert();
}else{
//Group Available..
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 04:12 PM
Following Client Script and Script Include will check if a group exists.
Client Script. I have a onChange() script on single line variable accepting group name to check.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
try {
var ajax = new GlideAjax('GroupUtil');
ajax.addParam('sysparm_name', 'existsGroup');
ajax.addParam('sysparm_group_name', newValue);
ajax.getXMLAnswer(function(answer) {
if (answer.length > 0) {
g_form.setValue('reply', answer);
}
});
} catch (e) {
alert(e.message);
}
}
Script Include:
var GroupUtil = Class.create();
GroupUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
existsGroup: function() {
var groupName = this.getParameter('sysparm_group_name');
var grGroup = new GlideRecord('sys_user_group');
if (grGroup.get('name', groupName)) {
return true;
}
return false;
},
type: 'GroupUtil'
});
Execution result:
1. When group exists, Reply is set to "true".
2. When group does not exist, Reply is set to "false”。
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 05:43 AM
Thanks for the help, it worked! I just have one more doubt, I would like that instead of a field it was just an error message, but I can't do the validation, I tried to put in the "IF" answer == true but it doesn't work, how would it be?