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

it will not work as your trying gliderecord in client side. create client script to get the value from server to client side by using use glideajax


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

any other method through which i can use encoded queries through client side or there is no option  

no you cannot you need to use server side methods to use addEncodedQuery. Create a client script and a script include using glideajax you can get the value which you need.


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

ohh okay thank you  it means

getEncodedQuery() and setEncodedQuery() is of no use in client side

HrishabhKumar
Kilo Sage

Hi @Murtaza Saify ,

You are using wrong method in second line. it should be addEncodedQuery instead of getEncodedQuery. Update that and your code will work correctly.

I'm pasting the corrected code bewow.

function onLoad() {

    var gr = new GlideRecord('cmdb_ci');
    gr.addEncodedQuery('cost>10000');
    gr.query();
    var str;
    var count=0;
    while (gr.next()) {
        str = str+ ' and  ' + gr.name;
        count++;
    }
    alert(str);
    alert(count);

}

 

Hope this helps you.