gr.next() returns false regardless of what I do!

kim-lindgren
Kilo Sage

I have a client script with a simple GlideRecord query that refuses to work. I have tried many different variants, such as: querying a different table, using various addQuery() filters, exchanging if for while, and more. I feel I must be missing something very basic here but I cannot figure it out.

 

Best regards,

Kim 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var envGr = new GlideRecord('cmdb_ci_environment');

    envGr.query();

    alert(envGr.next()) //returns false

    if (envGr.next()) {
        alert("Come on"); //Does not run
    } else {
        alert("Empty") //Runs
    }

}
1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@kim-lindgren You are trying to run a GlideRecord query inside a client script, this might work for the native platform but would certainly not work in case of Service Portal.

 

I suggest you to create a Client callable script include and all its method using a GlideAjax call from the client script.

 

Also following line might now work as it does not have semicolon in the end.

alert(envGr.next()) //returns false

 

Replace with 

 

alert(envGr.next()); //returns false

 

 Hope this helps.

View solution in original post

6 REPLIES 6

Shruti
Mega Sage
Mega Sage

Hi,

Please avoid using GlideRecord in client script.

Best practice is to use GlideAjax

Danish Bhairag2
Tera Sage
Tera Sage

Hi @kim-lindgren ,

 

Using GlideRecord in Client script is not a best practice. Kindly use GlideAjax from client script to perform a Glide record query in script include.

Coming to ur issue, can u check if there is a "next" field available in cmdb_ci_environment table. If it is present, please use gr._next() & try it should work.

 

Mark my answer as helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

Sandeep Rajput
Tera Patron
Tera Patron

@kim-lindgren You are trying to run a GlideRecord query inside a client script, this might work for the native platform but would certainly not work in case of Service Portal.

 

I suggest you to create a Client callable script include and all its method using a GlideAjax call from the client script.

 

Also following line might now work as it does not have semicolon in the end.

alert(envGr.next()) //returns false

 

Replace with 

 

alert(envGr.next()); //returns false

 

 Hope this helps.

Thanks, I will try that. What is the reason why you can use GR in client script unless it is in Service Portal?

 

I never experienced that semicolons made a difference though. In what situations could a missing semicolon cause the code to fail?