- 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:56 AM
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?
Best regards
Suyog

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