- 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-11-2020 11:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2020 12:16 PM
Thank you Muhammad. I didnt catch it while changing the code.
Much Appreciated 🙂

- 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-14-2020 10:10 PM
Thank You Hozawa,
Can you please provide the difference between the two methods below?
ga.addParam('user_id', newValue);
ga.getXMLAnswer(function(answer) {
if (answer == "true") {
ga.addParam('sysparm_user_name', newValue);
ga.getXML(callBack);
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
I would like to understand the difference between them.
Thanks,
pK.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2020 02:46 AM
Hi PK,
Above link has worthy information around this
Thanks & Regards,
Sharjeel
Muhammad