How to write client script for planned end date can't be more than 2 month from planned start date

PRAGHATIESH S
Tera Expert

Hi,

 

I have created one check box (u_type) on the change form (change_request table).

(1) If check box is false...planned end date can' be set more than 2 months from planned start date.

(2) If check box is true....Planned end date can't be set more than 6 months from planned start date. if we set less than 6-month, error message should get show.

Can anyone help me on the client script?

1 ACCEPTED SOLUTION

Pratik Malviya
Tera Guru

Hi @PRAGHATIESH S ,

 

You can achieve this by UI policy easily, You need to write 2 UI policy for both these condition.

 see 1 of the I have created other you can replicate.

PratikMalviya_0-1674809141972.png

 

PratikMalviya_1-1674809198725.png

Please mark correct if it works for you.

 



 

View solution in original post

5 REPLIES 5

Shashank_18
Mega Guru

use below snippet :

 var gd = new GlideDate();
    gd.addMonths(2); // or gd.addMonths(6); 
    current.u_estimated_time_of_delivery = gd;

    var gdt = new GlideDateTime();
    gdt.addMonths(2); // or gdt.addMonths(6); 

Not applicable

var startDate = new Date(start);

var endDate = new Date(end);

var diff = endDate.getTime() - startDate.getTime();

var diffInMonths = diff / (1000 * 60 * 60 * 24 * 30);

if (diffInMonths > 2) { gs.addInfoMessage("Error: planned end date cannot be more than 2 months from planned );

Mark helpful or correct.

Aman Kumar S
Kilo Patron

Hi @PRAGHATIESH S ,

Did you try with UI policy, it is can very easily be configured in UI policy using filter condition.

 

 

No Code date validations through UI Policies