GlideRecord is not working on catalog client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 04:50 AM
Hello All,
GlideRecord is not working on catalog client scripts.
I have written below code in on Load Client script,
function onLoad() {
//Type appropriate comment here, and begin script below
var gr= new GlideRecord('sys_user_group');
gr.query();
alert('count is'+gr.getRowCount());
//alert('count is'+gr.getRowCount());
}
It returns "0" value as Value is there in table,
I have tried this code in background script,it returns number of rows as available in table.
Please help
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:54 AM
Use GlideAjax instead of GlideRecord,
To my knowledge, GlideRecords themselves do not work in async mode, but Business Rules incorporating the use of GlideRecords can run in async mode.
Using GlideAjax instead of GlideRecords directly in client side scripts is still the better way to go - Client Script Best Practices - ServiceNow Wiki
Hope this will helps you....
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:57 AM
The use of GlideRecord in a client script is not best practice because GlideRecord is a server based query and it is inefficient for a client to perform server lookups. GlideAjax is a suggested alternative.
In your example you are trying to display something onLoad. An alternative if you truly need to display something on load would be a display business rule that can accomplish the same thing server side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:58 AM
Here is the difference between both:
GlideAjax :
- GlideAjax class allows the execution of server-side code from the client. GlideAjax calls pass parameters to the script includes, and, using naming conventions, allows the use of these parameters.
GlideRecord
- is used for database operations instead of writing SQL queries.
- is an object that contains zero or more records from one table. Another way to say this is that a GlideRecord is an ordered list.
Please Refer:
what is the difference between the glide record and glide Ajax ?
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 09:37 AM
Please close this thread, then only this could be useful for other community users.
if i answered to your query please mark my response as correct.
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke