Client Script - addEncodedQuery

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2015 07:21 AM
I have an onSubmit client script that I am trying to run the following code in ...
function onSubmit() {
var modelMatch = false,
curModel = g_form.getValue('u_discovered_model'),
ciList = [],
encQuery = "nameLIKE" + String(curModel) + "^ORmodel_numberLIKE" + String(curModel),
gr = new GlideRecord("cmdb_model");
gr.addEncodedQuery(String(encQuery));
gr.query();
alert('pre query');
while (gr.next()) {
ciList.push(String(gr.name));
modelMatch = true;
}
if(modelMatch){
var listModels = '';
for(i=0;i<ciList.length;i++){
listModels = listModels + ' : ' + String(ciList[i]);
}
if(confirm('Are you sure this model does not already exist?\nThese models are already in Service Now : ' + listModels + '\nClick CANCEL if you would like to change to one of these')){
return true;
}
else{
g_form.showErrorBox("u_discovered_model", 'Please Change the model to an existing one. Such as : ' + listModels);
return false;
}
}
}
I reach line 6 but it falls over on the encoded query (line 7).
I've checked my query and it is as expected and works when I use it to query the table directly (in list view).
Can anyone see where I'm going wrong?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2015 07:38 AM
Hello Daryll,
GlideRecord in client scripting is very limited http://wiki.servicenow.com/index.php?title=Client_Side_GlideRecord
I would suggest you to use GlideAjax: http://wiki.servicenow.com/index.php?title=GlideAjax
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2015 08:10 AM
you are using "," instead of ";" in line 3,4,5.
once you fix that it should work. addEncodedQuery is supported by client script so you should not have any issues with that.
But if there is an option go for GlideAjax instead of GlideRecord.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2015 08:23 AM
Daryll,
Nisheeth is right, although addEncodedQuery is not documented in the wiki page you can use "addQuery" with just one argument (Your encoded string)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2015 06:52 AM
Lines 3,4,5 & 6 are not a problem. You can use "," instead of ";" when declaring variables one after another as long as your last variable is closed with ";"