catalog client script to check the duplicate value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 04:40 AM
Hi,
I have created a Catalog item which creates a new group. I want to create a Catalog client script to pop-up an error when user enters new_group_name which already exists in the group table.
Could you please suggest how to achieve this.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 04:54 AM
Hello @Ashwitha gandla ,
Using an on change client script and must make a GlideAjax call to a script include and return the information you desire.
For this example, the below would work:
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('getgroupinfo');
ga.addParam('sysparm_name','groupname');
ga.addParam('sysparm_group',newValue);
ga.getXMLAnswer(dosomething);
function dosomething(response){
var answer = response;
if (answer){
alert('Group name already exists');
}
}
}
Script Include: (Ensure Client Callable):
var getgroupinfo = Class.create();
getgroupinfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
groupname: function() {
var userGR = new GlideRecord('sys_user_group');
if (userGR.get('name', this.getParameter('sysparm_group'))){
return true;
}
},
type: 'getgroupinfo'
});
If my reply helped with your issue please mark helpful 👍 and correct if your issue is now resolved. ✅
By doing so you help other community members find resolved questions which may relate to an issue they're having.
BR,
Nayan
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.