- 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-03-2016 11:40 PM
Hi Neha,
GlideRecord is not supported in scoped application. I would recommend you to use GlideAjax to achieve the above solution. More info here.
http://wiki.servicenow.com/index.php?title=GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2016 11:50 PM
Hi Neha,
As Pradeep mentioned, GlideAjax is the best practice. GlideRecord is not recommended for client scripts in general (even in global) due to its performance impact.
Client Script Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2016 11:58 PM
Hi Robert/Pradeep,
I have already gone through the link. I am new so may be wrong but seems GlideAjax doesn't query another table. I need a way to query another table from Client Script.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2016 12:04 AM
Hi Neha ,
It does queries other tables..
You have to put your same code the Script include and call it from Client script... Also check client callable true in Script include.
Sample code:-
var ga = new GlideAjax('scriptinclName');
ga.addParam('sysparm_name','functionName');
ga.addParam('sysparm_user_name',newValue);
In script include something like below.
var scriptinclName= Class.create();
scriptinclName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
functionName: function() {
return "Hello " + this.getParameter('sysparm_user_name') + "!";
},
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
Thanks,
Deepa