The CreatorCon Call for Content is officially open! Get started here.

Date should not be in past

Sirri
Tera Guru

Hi All,

 

As per my requirement Date should not be selected as past if select we should want to clear the date.

 

If I do with  UI Policy with Run Script I'm getting but I should want get with On change client script.

 

Please let us know how can i get this requirement with out using ui policy for this

 

Thank you

9 REPLIES 9

Harish KM
Kilo Patron
Kilo Patron

Hi @Sirri , you can use the below script

var currentDate = new Date().getTime();
    var refreshDate = new Date(g_form.getValue('variableName')).getTime();
    if (refreshDate <= currentDate) {
        var message = 'Cannot select past Date';
       
        g_form.clearValue('variableName');
        g_form.showErrorBox('variableName', message);
       
    }
Regards
Harish

Hi@Harish KM ,

 

I have tried with this but it not taking current date.

when ever select current date it will showing as error.

but my requirement is we cannot  select past date only but we can select current date

Thank you

Gi @Sirri share your client script may be your missing <= in condition

Regards
Harish

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Just wondering why you want to do this with Client Script? If you could do this with UI Policy, which is no code, easier to understand for others, less time-consuming, etcetera, why then choose Client Script? Or do you have a requirement behind this that makes using Client Script necessary?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn