I am not getting correct answer through encoded query in glide record
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 05:07 AM
function onLoad() {
var gr = new GlideRecord('cmdb_ci');
gr.getEncodedQuery('cost>10000');
gr.query();
var str;
var count=0;
while (gr.next()) {
str = str+ ' and ' + gr.name;
count++;
}
alert(str);
alert(count);
}
Here is my code whats wrong with it
17 REPLIES 17
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 05:58 AM
Try addQuery instead of addEncodedQuery.
function onLoad() {
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('cost', '>', '10000');
gr.query();
var str;
var count=0;
while (gr.next()) {
str = str+ ' and ' + gr.name;
count++;
}
alert(str);
alert(count);
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 06:05 AM
Try this :
Script include : getCount
getRecCount : function(){
var counts = [];
var gr = new GlideRecord('cmdb_ci');
gr.getEncodedQuery('cost>10000');
gr.query();
var str;
var count=0;
while (gr.next()) {
count.push(str+ ' and ' + gr.name);
count++;
}
return counts.toString();
}
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 06:35 AM
Hi @Murtaza Saify ,
Please try below code
var gr = new GlideRecord('cmdb_ci');
gr.addEncodedQuery('cost>10000');
gr.query();
var name = [];
var count = 0;
while (gr.next()) {
name.push(gr.name.toString());
count++;
}
gs.print("name = " + name);
gs.print("count = " + count);Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
