Catalog item

Nikita50
Tera Expert

Hi All,

 

How to put validation that a particular catalog item cannot be submitted more than thrice in a day?

 

 

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Nikita50 

Apply user criteria and check using user criteria script how many RITMs are there for logged in user for today

If more than 3 then hide it from portal itself so that they can't submit

Then add this user criteria in Available for related list

		var rec = new GlideRecord('sc_req_item');
		rec.addQuery('cat_item.name', 'Your Item Name');
		rec.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
		rec.addQuery('requested_for', user_id);
		rec.query();
		if (rec.getRowCount() > 3)
		    answer = false;
		else
		    answer = true;

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

not for one user.. in a day it should not be submitted more than thrice

@Nikita50 

then comment this line and the logic should work fine

		rec.addQuery('requested_for', user_id);

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

Hi Ankur ,

 

i have written following script include:

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

    checkSubmissionLimit: function() {

    var gr = new GlideRecord('sc_req_item');
    gr.addEncodedQuery('');
    gr.query();
    if (gr.getRowCount() > 3)
    answer =  false;
    else
    answer = true;

    },

    type: 'CatalogSubmissionLimit'
};
 
 
 
following on client script :
 
function onSubmit() {
    var ga = new GlideAjax('CatalogSubmissionLimit');
    ga.addParam('sysparm_name', 'checkSubmissionLimit');
    ga.getXMLAnswer(function(response) {
        if (response == 'false') {
            alert('You have already submitted this item three times today.');
            g_form.setAbortAction(true); // Prevent form submission
        }
    });
}
 
 
but there is some error.