Need help with getting a total count value in Lookup Select Box variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 03:35 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 10:14 PM
Suggestion code 1 and 2 did not work so I try suggestion code 3 and I'm still could not get it to work. could you please help review what I have done, could be some line I missed type:
CATALOG CLIENT SCRIPT:
SCRIPT INCLUDE:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 09:05 PM
Hello @Annie10 ,
I have same kind of Script it might help you, Lookup select box referring to sys_user, lookup value is department, so once we select any department in look value, it will display the count of associated users belonging to that selected department. ref script
Client Script : (onChange on Lookup select box)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
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('select_dept')); // 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 : It should be client callable
var demoScriptInclude = Class.create();
demoScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSysUserCount: function() {
var selectedDept = this.getParameter('sysparm_selected_dept');
gs.info("Selected dept is"+ selectedDept);
var sysUserGR = new GlideRecord('sys_user');
sysUserGR.addQuery('department', selectedDept);
sysUserGR.query();
var associatedSysUserCount = 0;
while (sysUserGR.next()) {
associatedSysUserCount++;
}
gs.info("Selected dept count is"+ associatedSysUserCount);
return associatedSysUserCount.toString();
},
type: 'demoScriptInclude'
});
O/P
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 10:29 PM
Hello @Chetan Mahajan
Thank you for sharing your codes. I'm totally lost after reviewing the codes.
Catalog Client Script - OnLoad:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 10:39 PM
Hello @Annie10 ,
could you please share snapshot of your CatLog item where Lookup box is placed ? Because select lookup box capability select single value. so which count you are expecting. are you looking for count of u_book table on catalog form ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 07:43 AM
This catalog item is still under developing. Here are the steps we have done so far.
VARIABLES:
SELF-SERIVCE PORTAL:
The workflow should be similar as your. Once the form loaded, it shows the number of books that the current student has in Number of Book field.
When we select a different user, number of books changes accordingly.
We need help on the total count of the number of book such as an Alert so that we can use it to develop further programming logic.
Thank you again for your support.