Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Limit submission of intake form after a certain time

Vaishali 11
Tera Guru

Hi,

Is it possible to limit the submission of an intake form after it's been the first 10 days or 15 days of the month? If yes how it can be done?

Thanks in advance!!

1 REPLY 1

Viraj Hudlikar
Tera Sage
Tera Sage

Hello @Vaishali 11 

 

Yes, it's possible by writing a Scripted User Criteria (to hide the item entirely) and On Submit Client Script (to block submission with a message), incase if admins are able to see item or sometimes cache issue causes to display item.

VirajHudlikar_0-1764158308084.png

 

Script for User Criteria:

answer = checkDate();
function checkDate() {
    // Get Current Date/Time
    var gdt = new GlideDateTime();
    // Get the Day of the Month (Local time or System time depending on requirement)
    // using getDayOfMonthLocalTime() handles the user's timezone better
    var day = gdt.getDayOfMonthLocalTime(); 
    
    // Check if day is within the limit (e.g., 15)
    if (day <= 15) {
        return true; // Allow access
    }
    return false; // Deny access
}

 

VirajHudlikar_1-1764158378785.png

 

function onSubmit() {	
	// This script checks the client date. 
    // For strict security, use GlideAjax to check Server Time to prevent timezone hacks.
    
    var limitDay = 15; // Set your limit day here
    var today = new Date();
    var currentDay = today.getDate(); // Returns day of month (1-31)

    // If today is after the limit
    if (currentDay > limitDay) {
        // 1. Add a prominent error message
        g_form.addErrorMessage('Intake for this form is only allowed between the 1st and the ' + limitDay + 'th of the month. Submissions are currently closed.');
		return false;        
    }
}

 

Below are some screenshot of working and configuration done over a catalog item named "Test Item".

VirajHudlikar_3-1764158733597.png

VirajHudlikar_4-1764158761816.png

Below results over portal when I impersonate with ITIL User:

VirajHudlikar_2-1764158678198.png

 

Below results when I try to test item being admin I can see but we want to avoid submission in case it has cache issue or someone with admin role try to access item then result is as seen below.

VirajHudlikar_5-1764158915064.png

 

If my response has helped you, hit the helpful button, and if your concern is solved, do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.