in change table start_date field should show 4 days date select options only how to do that?

Siddiqbasha
Tera Contributor
 
1 ACCEPTED SOLUTION

SN_Learn
Kilo Patron
Kilo Patron

Hi @Siddiqbasha ,

 

Please try the below in UI policy:

 

SN_Learn_1-1731164298438.png

 

In the Script section:

 

SN_Learn_3-1731164726459.png

 

 

function onCondition() {
    g_form.clearValue('start_date');
    g_form.showFieldMsg('start_date', 'Selected Planned start date cannot be more than 4 days!', 'error', true);
}

 

 

Result:

SN_Learn_4-1731164777614.pngSN_Learn_5-1731164798114.png

 

 

When more than 4 days selected:

SN_Learn_6-1731164824707.png

SN_Learn_7-1731164844850.png

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Siddiqbasha 

 

Instead of doing this, better out a UI policy that the start date can be greater than 4 days and if user select more than 4 days show a message, that is easy and quick.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

If I select planned date more than 4 days it should not me allow to select.

Hello @Siddiqbasha 

In ServiceNow, disabling specific dates directly within the calendar picker isn’t supported without using DOM manipulation, which isn’t recommended. However, you can achieve similar functionality by setting up a UI Policy and UI Policy Action to validate the date selection.

Here's how:

  1. Create a UI Policy that runs on form load or on change of the start_date field.
  2. In the UI Policy Action, configure a condition to check if the selected date is outside the allowed four-day range.
  3. If an invalid date is selected, clear the date field or display an error message.

This approach requires little to no code and keeps the setup manageable within ServiceNow’s best practices.

 

*************************************************************************************************************
"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

Thank You
Juhi Poddar
****************************************************************************************************************

SN_Learn
Kilo Patron
Kilo Patron

Hi @Siddiqbasha ,

 

Please try the below in UI policy:

 

SN_Learn_1-1731164298438.png

 

In the Script section:

 

SN_Learn_3-1731164726459.png

 

 

function onCondition() {
    g_form.clearValue('start_date');
    g_form.showFieldMsg('start_date', 'Selected Planned start date cannot be more than 4 days!', 'error', true);
}

 

 

Result:

SN_Learn_4-1731164777614.pngSN_Learn_5-1731164798114.png

 

 

When more than 4 days selected:

SN_Learn_6-1731164824707.png

SN_Learn_7-1731164844850.png

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.