- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:23 AM
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
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:30 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:28 AM
Hi,
Please avoid using GlideRecord in client script.
Best practice is to use GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:29 AM - edited 10-16-2023 01:32 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:30 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:43 AM
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?