
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 10:33 PM
Hi,
I'm needing to do a check on a catalog item as it is being filled in.
I have a text field called:
group_name
What I want to do is after the field is filled in have it check the sys_user_group to see if a group name already exists that is the same.
I was thinking that I'd be able to do it via an onchange client script, but can't seem to get that to work.
Ultimately I want a message to come up advising that the name is already being used if it is found and to just let the person carry on if it is not found.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 11:26 PM
it means the value is not getting passed
Also I have updated the client script line as this
if(answer.toString() == 'true'){
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 12:57 AM
Thank you for that, I've tried it and get no result at all.
Does the script include require a specific name to be called?
Also the role added to it, does that matter?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 01:31 AM
please share your scripts and also the screenshots for script include and client script configuration.
It should work fine if you are having the script include as client callable
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 04:30 PM
Here is the code that I'm using:
Script Include: Client Callable is checked.
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var name = this.getParameter('sysparm_groupName');
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name', name);
gr.setLimit(1);
gr.query();
return gr.hasNext();
},
type: 'checkRecords'
});
Catalog Client Script: set on change for variable: group_name
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('group_name '); // give here correct variable name
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_groupName', newValue);
ga.getXMLAnswer(function(answer){
if(answer == 'not found'){
var message = 'This group is already present in groups table';
g_form.clearValue('group_name'); // give here correct variable name
g_form.showFieldMsg('group_name ',message,'error', true);
}
});
//Type appropriate comment here, and begin script below
}
Here are screen shots
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 09:08 PM
did you check what came in alert?
Did you check by adding gs.info() in script include if it's getting called or not?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 10:02 PM
So I just put gs.info() into the script include as follows:
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var name = this.getParameter('sysparm_groupName');
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name', name);
gr.setLimit(1);
gr.query();
gs.info();
return gr.hasNext();
},
type: 'checkRecords'
});
It didn't appear to give any info after checking the logs, however the following does occur when I finish filling in the group_name field:
So checking the Dev logs on the page I get the following:
And in the logs: