Selected Date and Time should be one hour in Advance

Lucky1
Tera Guru

Hello all,

 

I have created a date and time field and the selected date and time should be one-hour in advance.

So, I have created a on Submit client script and it's not working. 

Can someone help me please?

Lucky1_0-1744098367906.png

 

 

Regards,

Lucky

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Lucky1 

why not use UI policy?

Something like this and use Script field

AnkurBawiskar_2-1744099625931.png

 

 

AnkurBawiskar_3-1744099640435.png

 

My current time is approx 1:06:00 AM so it gave me error when I selected time within 60mins (1hour)

AnkurBawiskar_4-1744099691027.png

 

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

4 REPLIES 4

Shivalika
Mega Sage

Hi @Lucky1 

 

GlideDateTIme is a server side script and not client side. You need to modify it in a script include or BR and send it here. You can only perform some basic modifications in the client side, like changing the formats. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Ankur Bawiskar
Tera Patron
Tera Patron

@Lucky1 

why not use UI policy?

Something like this and use Script field

AnkurBawiskar_2-1744099625931.png

 

 

AnkurBawiskar_3-1744099640435.png

 

My current time is approx 1:06:00 AM so it gave me error when I selected time within 60mins (1hour)

AnkurBawiskar_4-1744099691027.png

 

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

but this method is not working in esc portal view it is only working only in record producer try button view

Ankur Bawiskar
Tera Patron
Tera Patron

@Lucky1 

If you still want to use onSubmit then update your script as this

function onSubmit() {

    var mydate = g_form.getValue('date_and_time');
    var minutes = 60;

    var dt = new Date(getDateFromFormat(mydate, g_user_date_time_format)).getTime() + minutes * 60000; // add 60mins to date and then compare
    var nowTime = new Date().getTime();

    if (dt < nowTime) {
        alert('date should be after 60 from now');
        return false;
    }
}

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