- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2020 04:24 PM
Hi All,
I have a requirement to check if a userid already exists and if it exists an error should be thrown user id already exists. There is a field on a catalog item and when a user enters the user id like pkmar00 it should check behind the scenes and throw an error and clear out the field value.
Kindly please help me.
Thanks & Regards.
Praveen.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2020 11:02 AM
Try this. Tested it with "abraham.lincoln", "donald.trump"
Script Include:
var checkUserExists = Class.create();
checkUserExists.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateUser: function() {
var user_id = this.getParameter('user_id');
var gr = new GlideRecord("sys_user");
gr.addQuery("user_name", user_id);
gr.query();
if (gr.next()) {
return true;
} else {
return false;
}
},
type: 'checkUserExists'
});
UI Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('checkUserExists');
ga.addParam('sysparm_name', "validateUser");
ga.addParam('user_id', newValue);
ga.getXMLAnswer(function(answer) {
if (answer == "true") {
g_form.clearValue('user_id');
g_form.showFieldMsg('user_id', 'User already exists.');
}
});
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2020 08:57 PM
Check the following article. In a nutshell, getXML will retrieve the entire xml document while getXMLAnswer will only retrieve a returned value. That's why getXML will need to be parsed to get the value while getXMLAnswer do not.
Because getXMLAnswer is returning less data and require less processing on the client side, it is preferred over getXML when just retrieving a value.
Note, that it is still necessary to use getXML to return an object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2020 11:10 AM
Hii you have to write a script include & return true/false from it if user exist return true; else return false Call it onchange script.
var isUserExists = Class.create(); isUserExists.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize:function(){
},
validate: function()
{
var user_id = this.getParameter('user_name');
var gr = new GlideRecord("sys_user"); gr.addQuery("user_name", user_id);
gr.query();
if (gr.next())
{
return true;
}
else {
return false;
}
},
type: 'isUserExists'
});