Need help with getting a total count value in Lookup Select Box variable.

Annie10
Tera Contributor

Hello,

Our Catalog Item contains a Lookup Select Box variable which getting the data from a custom table(u_books)

We need help on getting the total count of the lookup box value after a form loaded so that we can write conditions.

Could someone please provide suggestion?

we appreciate your help

 

12 REPLIES 12

if you just want count of u_book record, simply fetch as below 

 getBookCount: function() {
        var booksCount;
        var gr=new GlideRecord("u_book"); //glide the table you want to count rows
              //gr.addQuery('active', true); //shows all active records
                 gr.query(); // query the condition

 gs.print(gr.getRowCount()); // counts all the active incidents and prints the number
          booksCount=gr.getRowCount();
        return booksCount.toString();
    },

Hi @Chetan Mahajan 

Do I remove the entire code in the Catalog Client Script and replace them with the new provided code?

Annie10
Tera Contributor

Hello,

Can someone please continue to provide assistance?  I have a select lookup box variable that I'm trying to get the total count when form load. I'm getting a zero data return in an Alert. 

Annie10_0-1692159386378.png

 

Here are the codes, please help review it and make necessary correctly.  Thank you

 

Catalog Client Script:

function onLoad() {
    var ga = new GlideAjax('demoScriptInclude'); // Replace with your Script Include name
    ga.addParam('sysparm_name''getSysUserCount'); // Replace with your server-side method name
    ga.addParam('sysparm_selected_dept', g_form.getValue('number_of_book')); // pass lookup select box value
    ga.getXMLAnswer(function(response) {
    
       // Now you have the total count of sys_user records, you can use it for your conditions
        alert('Total Sys User Count:', response);
    });
}
 
Script Include:
var demoScriptInclude = Class.create();
demoScriptInclude.prototype = {
    initialize: function() {},
 
    getBookCount: function() {
        var booksCount;
        var gr = new GlideRecord("u_books"); 
        gr.query(); 

        gs.info(gr.getRowCount()); 
        booksCount = gr.getRowCount();
        return booksCount.toString();
    },
    type: 'demoScriptInclude'
};