Count the amount of records from the table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2022 06:16 AM
Hi All,
I am trying to get the number of records from table sc_req_item (records from last 30 days). I think I need to create this by Client Script and Script Include because when I will have number of records then I want to add some conditions to check what number of this records have field ABC with value true and then show the field in the form from another table, so I created Client Script and Script INclude like this to count the whole records from sc_req_item, but it doesn't work..:
Client Script:
function onLoad() {
var ajax = new GlideAjax('calculateRITM');
ajax.addParam('sysparm_name', 'getCount');
ajax.getXML(IncCount);
function IncCount(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
Script Include:
var calculateRITM = Class.create();
calculateRITM.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCount: function() {
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('sys_created_onONLast 30 days@javascript:gs.beginningOfLast30Days()@javascript:gs.endOfLast30Days()');
gr.query();
var answer = '';
while (gr.next()) {
answer = gr.getRowCount();
}
return answer;
},
type: 'calculateRITM'
});
What is wrong?
Thanks in advance for help
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 12:36 AM
Hi
Was I able to answer your doubt?
If my reply has solved your issue then
I urge you to rate my answer so that other community users facing similar issues might benefit from this!!
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 02:50 AM
Thanks a lot for help! I was trying with corrects from you but now in alert I can see " [object Object] " instead of amount of records 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 12:41 AM
what's your business requirement to get the count?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 02:53 AM
I have a field ABC in Catalog Item form and when this field is 'true' then field EFG appears in requested item form.
Requirement is to see button EFG only if amount of requested items with field EFG is not bigger than 10% of all requested items from last 30 days.
That's why I stared from get the amount of RITMs from last 30 days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 03:04 AM
Hi,
try to convert the returned value to integer using parseInt()
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader