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 ?

 

Using the  After BR but i need to same scenaior  build the client side script.

 

// 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();
  {
 
  gs.print('You have created a total of ' + totalRecords + ' problem records.');   // Show the message
}
 
Any idea help me.
6 REPLIES 6

Mark Manders
Mega Patron

What is the requirement behind this? What issue will showing this information solve? 

You are running client side scripts to show a user what he already knows (for which you probably should use GlideAjax, because using gliderecord isn't best practice.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Sandeep Rajput
Tera Patron
Tera Patron

@Ram012 You can either use a combination of g_scratchpad +Display business rule + client script to show this information to the user or use GlideAjax call in client script to call a server side script include to get this information. 

Hi Sandeep ,

 

Thanks for quick response , but can you share the exact code.

tripu
Tera Expert

Hello,

 

I recommend using GlideAjax. Please find the below scipt.

 

Client Script:

var user = g_form.getUniqueValue();

var ga = new GlideAjax('script_include_name');

ga.addParam('sysparm_name', script_include_function_name);

ga.addParam('sysparm_user', user);

ga.getXML(callback);

function callback(response){

var answer = response.responseXML.documentElement.getAttribute("answer"); // 'answer' variable contains the total number of problem records.

 

Script Include: Should be client callable.

script_include_function_name: function() {

var user = this.getParameter('sysparm_user');

var gr = new GlideRecord('problem');
gr.addQuery('opened_by', user);
gr.query();
var totalRecords = gr.getRowCount();

return totalRecords;

}