- 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 12:46 AM
Hi Ashutosh,
It is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2016 12:26 AM
Also check by prompting that what you are getting in newValue ,sys id or name,accordingly query table.
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 12:51 AM
Hi Deepa,
I followed your steps and getting 'sysid' as null in the alert.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2016 01:07 AM
in client script sysid is NULL....check that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2016 01:09 AM
I wrote below Client Script and there sysid is null in the alert.
Client Script : -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var sysid = g_form.getValue('sys_id');
var ga1 = new GlideAjax('ValidateUser');
ga1.addParam('sysparm_name', 'checkUser');
ga1.addParam('sysparm_newValue', newValue);
ga1.addParam('sysparm_sys_id', sysid);
alert('newValue '+newValue +'sysid ' +sysid);
ga1.getXML(UserParse);
function UserParse(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
//Type appropriate comment here, and begin script below
}