Check if Name of Supportgroup is already in Use
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello everybody,
We have a Requirement for a Catalog Item, to enable Users to order a new support group.
The users can enter their preffered group name into a single line text field for which i would like to implement a validation, so that group names must me unique and the User receives an error message if they try to enter a group name that already exists. Can anybody assist with a catalog client script for this use case?
Kind regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
You can achieve this by using a Catalog Client Script and a Client Callable Script Include that checks whether the entered group name already exists in the sys_user_group table.
Below is a working example:
1.Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('CheckGroupName');
ga.addParam('sysparm_name', 'checkIfGroupExists');
ga.addParam('sysparm_group_name', newValue);
ga.getXMLAnswer(function(response) {
if (response === 'true') {
g_form.showFieldMsg('your variable name', 'This group name already exists. Please choose a different name.', 'error');
g_form.setValue('your variable name', ''); // optional: clear the field
} else {
g_form.hideFieldMsg('your variable name', true);
}
});
}
2.Script Include:
var CheckGroupName = Class.create();
CheckGroupName.prototype = {
initialize: function() {},
checkIfGroupExists: function() {
var groupName = this.getParameter('sysparm_group_name') || '';
var grp = new GlideRecord('sys_user_group');
grp.addQuery('name', groupName);
grp.query();
if (grp.next()) {
return 'true';
}
return 'false';
},
type: 'CheckGroupName'
};
— Sanjay J
