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-14-2015 05:21 AM
Well in that case , you need look upon the field - "u_discovered_model. What is it? is it a reference field?
If yes, then it won't work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2015 06:22 AM
It is not a referenced field it is a string. I've checked my g_form.getValue() returns and I get the string that was typed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2015 04:59 AM
Has anyone managed to get an .addOrCondition() to work?
I've seen it in the wiki but any time I've tried it it falls over.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2015 05:14 AM
Hi Daryll,
Unfortunately you rare limited to use only the method listed here:
http://wiki.servicenow.com/index.php?title=Client_Side_GlideRecord
You will need to use an encoded query by using the addQuery method

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2015 06:26 AM
I've tried adding the encoded query in to an addQuery() but I get very odd results with the or condition in the encoded query string and it's definitely not matching the conditions given.