Client script

Ram012
Tera Contributor

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 .

2 REPLIES 2

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

Soni Tushar
Tera Guru

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!