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 able to get answer in client side

Community Alums
Not applicable

Hi @Murtaza Saify ,

check if you are using correct query inside addEncodedQuery.

 

yeah as i am testing using simple quries 

Community Alums
Not applicable

Hi @Murtaza Saify 

Try using addQuery instead of addEncodedQuery. I've pasted the code below.

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

}

nikhilsoni973
Tera Contributor

Hi,

 

You cannot use GlideRecord in Client script. Use GlideAjax and use GlideRecord code in Script include and call that script include using GlideAjax.

 

https://www.youtube.com/watch?v=KJy_d-3Kf7k

 

If this Answer is helpful then mark it as correct!