how to validate group name of group table on catalog form when group name is given ,it should check if the group name already exists or not,if it gets it should get error message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 04:19 AM
when group name is given,the field should check for its existing group names,if group name already exists,it should get error message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 12:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 01:32 PM
Hi,
An onChange client script on the catalog field where group name is entered:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userGroups = new GlideAjax("UserGroups"); // script include name
userGroups.addParam("sysparm_name", "doesGroupExist"); // script include function to call
userGroups.addParam("sysparm_group", newValue); // value to pass to script include
userGroups.getXML(callbackXML);
function callbackXML(response) {
// get the response
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == "true") {
alert("This Group Name already exists");
g_form.setValue("groupname", "");
}
}
}
Then a script include (client callable):
var UserGroups = Class.create();
UserGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// check if group exists
doesGroupExist: function() {
var groupName = this.getParameter("sysparm_group").toString();
var groups = new GlideRecord('sys_user_group');
groups.addQuery('name', groupName);
groups.query();
if (groups.next()) {
return 'true';
}
},
type: 'UserGroups'
});
Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2022 02:10 AM
Hello
Let me know if my provided solution worked for you and if so mark as correct to close the thread. Otherwise let me know if I can help further.
Thanks