Client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 10:07 AM
when the user create the problem record , you should show the message of total number of records created by the currently log in user
for the problem table using OOB problem table ?
Client Script:function onLoad() {
// Get the current user's ID
var currentUser = gs.getUserID();
// Get the total number of problem records created by the current user
var gr = new GlideRecord('problem');
gr.addQuery('opened_by', currentUser);
gr.query();
var totalRecords = gr.getRowCount();
// Show the message
g_form.addInfoMessage('You have created a total of ' + totalRecords + ' problem records.');
}
Using client script but script not working .
Any idea above scenaior help me .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 10:12 AM - edited 08-17-2024 10:13 AM
Hi there,
Please don't apply GlideRecord in a Client Script, horrible bad practice! gs.getUsedID will also not work in Client Script.
Since it is a Client Script on the Platform UI, you could use scratchpad, and in a Business Rule determine the number of records and store that in the scratchpad.
Would that be an idea?
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 10:29 AM
Hello @Ram012 ,
No, using a client script is not possible. Try using the Before query Business Rule on the necessary table
(function executeRule(current, previous /*null when async*/ ) {
if (gs.getUser().isMemberOf('Group Name')) {
current.addQuery('sys_created_by', gs.getUser().getName());
}
})(current, previous);
If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!