Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

I am not getting correct answer through encoded query in glide record

Murtaza Saify
Tera Contributor
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

Not applicable

Hi @Murtaza Saify 

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);

}

Sohail Khilji
Kilo Patron

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....

LinkedIn - Lets Connect

Not applicable

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 

SarthakKashyap_0-1717508124997.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak