- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2016 11:37 PM
Hi Members,
I have a simple query. I am trying to query 'sys_user' table from my Custom form. I am querying 'user_id' of my current form to 'user_name' of 'sys_user' table. If the record is found then a user must get an alert that the same UserId exists in the system. For that I have written the below Client Script. Issue is :- I am getting a below error message in the 'user_id' field.
Error:-
Please Suggest.
Thanks,
Neha
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if(isLoading)
{
return;
}
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('user_name', newValue);
gr1.query();
myFunc();
function myFunc()
{
while(gr1.next())
alert('USER ID already exists');
}
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2016 12:34 AM
Hi Neha ,
Try something as below in script include:-
var sysid = this.getParameter('sysparm_sys_id') ;
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('sys_id', sysid )
gr1.query();
while(gr1.next())
gs.log('user exists');
return true;
}
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
Thanks,
Deepa

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2016 02:38 AM
Neha please check code once. after while if i put gs.log then code runs ,,,,if i remove it, it fails. so i asked you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2016 02:15 AM
Hi Neha,
ya code is correct now ...
You can remove below line from script include as you are not using sys_id anywhere..
var sysid = this.getParameter('sysparm_sys_id');
and below from CS
ga1.addParam('sysparm_sys_id', sysid);
Please mark Correct , hit Like and Helpful if you find my response worthy.
Thanks,
Deepa

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2016 02:34 AM
Hi there is one issue in this code what i am facing....correct me if i am wrong.
see below, after while i have brackets it, the code does not do inside the loop. and if no bracket then it works,
if u put gs.log before while it fails again....
var ValidateUser = Class.create();
ValidateUser.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
checkUser: function() {
var userid = this.getParameter('sysparm_newValue');
var sysid = this.getParameter('sysparm_sys_id');
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('user_name', userid);
gr1.query();
while(gr1.next())
{
return "UserID already existing";
}
},
_privateFunction: function() { // this function is not client callable
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2016 02:58 AM
There is only one statement after while() that is to be executed so there is no need of putting braces. If multiple statements to be executed then braces are required.
Anyways, i tried with braces also and it worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2016 02:59 AM
Thanks Deepa