Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Date selected should be within 2 days from current date in catalog client script.

Deepak Shaerma
Kilo Sage
Kilo Sage

Hi Community,

I make a date field variable on a catalog page and I need that date selected should be within 2 days from the current date. 

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @Deepak Shaerma ,

You can use the UI policy to achieve this.

1. Create a catalog UI policy and use below conditions on your date variable.

Conditions: User not to select the date 2 after days from now and not past date.

Screenshot (568).png

2. Script: Give your variable name and msg as per requirement.

function onCondition() {
    g_form.clearValue("start_date");
    g_form.showFieldMsg('start_date', "Please select date as 2 days from now", "error");
}

Screenshot (569).png

Result: Display msg user selects incorrect date.

Screenshot (570).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

5 REPLIES 5

Sagar Pagar
Tera Patron

Hi,

You have to create Catalog UI policy with condition as 

Date_variable relative after 2 days from now

 

Execute if true:

g_form.clearValue("date_variable");

g_form.showFieldMesaage("("date_variable", "date should be with in 2 days from now", "info");

 

Execute if false:

g_form.clearMessage();

 

 

Thanks,

Sagar Pagar 

The world works with ServiceNow

Community Alums
Not applicable

Pavankumar_1
Mega Patron

Hi @Deepak Shaerma ,

You can use the UI policy to achieve this.

1. Create a catalog UI policy and use below conditions on your date variable.

Conditions: User not to select the date 2 after days from now and not past date.

Screenshot (568).png

2. Script: Give your variable name and msg as per requirement.

function onCondition() {
    g_form.clearValue("start_date");
    g_form.showFieldMsg('start_date', "Please select date as 2 days from now", "error");
}

Screenshot (569).png

Result: Display msg user selects incorrect date.

Screenshot (570).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

@Pavankumar_1  I need to assign the assignment group to my catalog items. Help me in this..
if my (1) Catalog Item = Laptop so my Assignment group = IT ADMIN
and if Catalog Item = Mobile so my Assignment group = IT Mobile