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

For performance reasons Glide Record objects are not recommended to be executed at client end.

BTW are you able to get into if block now?

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.



Best regards

Suyog

@kim-lindgren GlideRecord is a synchronous API call which is blocked on the Service Portal. 

 

Regarding semicolon, it is a debatable topic in Javascript, sometimes compiler adds it from its own side but in other cases I have seen scripts failing please refer to this URL https://www.geeksforgeeks.org/semicolon-in-javascript/ for one such discussion.