Code is not working: I need to update total created requests count in a catalog variable.

ROS4349
Tera Expert

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:

------------------------------
var RecordCounter = Class.create();
RecordCounter.prototype = {
    initialize: function() {},

    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'
};
====================================================
Client Script:
 
function onLoad() {
    var ga = new GlideAjax('RecordCounter');
    ga.addParam('sysparm_name', 'getRecordCount');
    ga.getXMLAnswer(function(response) {
        g_form.setValue('available_slots_for_today', response);
    });
}
==============================================
 
Can you please help me in correcting above codes as per my requirement.
Attaching a requirement screenshot for your reference.
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ROS4349 

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

AnkurBawiskar_0-1704454370860.png

 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

@ROS4349 

Can you post a new thread for your new question and share all the details there along with script and screenshots

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader