- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 03:10 AM
Hi Folks,
Below are the Script include and Onload Catalog Client script.
I have a catalog single line text type variable "available_slots_for_today".
Requirement:
There is a group they can fullfil daily 10 request only.
When user is creating a request we need to show a field with how many requests created today and how many slots are available.
For that I need to update total created request count in current date. And to extend to this the request creation should not be exceed more that 10 request from a catalog item.
Script include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 03:32 AM
your script include should be client callable and then it will work. Currently it's not.
Ensure the client callable checkbox is true and update script as this
var RecordCounter = Class.create();
RecordCounter.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecordCount: function() {
var gr = new GlideRecord('sc_request');
gr.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
gr.query();
return gr.getRowCount();
},
type: 'RecordCounter'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 03:18 AM
Hi @ROS4349 ,
Code seems to be pretty fine. Can you share the output?
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 03:32 AM
Not getting any output.
available_slots_for_today variable shows empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 03:32 AM
your script include should be client callable and then it will work. Currently it's not.
Ensure the client callable checkbox is true and update script as this
var RecordCounter = Class.create();
RecordCounter.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecordCount: function() {
var gr = new GlideRecord('sc_request');
gr.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
gr.query();
return gr.getRowCount();
},
type: 'RecordCounter'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 03:43 AM
Thank you @Ankur Bawiskar.
Can you pls help me for below:
User should not select the date if 10 requests created today from a catalog item.
As per above screenshot it should show avalable slots to create record out of 10 requests.
if the requests count reaches to 10 per day, then user should get the populated error. And user should not select the date.