Cab date should not be past start date in change request
						
					
					
				
			
		
	
			
	
	
	
	
	
Options
			
				
					
	
			
		
	- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-08-2023 04:53 AM
Hi All,
I have a requirement where i have a field cab date which is a date field(OOB) and planned start date which is a date and time field (OOB)
I have to make sure that cab date should not be greater than planned start date.
I have written script below but it's not working.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   alert('Cab Date time',newValue);
  var plannedStartDate = g_form.getValue('start_date');
  var cabDate = g_form.getValue('cab_date');
  // Parse the dates
  plannedStartDate = new Date(plannedStartDate);
  cabDate = new Date(cabDate);
  // Check if cab date is after planned start date
  if (cabDate > plannedStartDate) {
    // Invalid date, show error message and revert cab date to planned start date
    alert('Cab date should not be after planned start date.');
    g_form.setValue('cab_date', '');
  }
  }
		1 REPLY 1
	
		
		
			
			
			
					
	
			Options
			
				
					
	
			
		
	- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
11-08-2023 05:29 AM
Hi @Meghant Rai
I am not a coder but can give you some path: Please chk OOTB validation.
Also need to note, CAB dates also auto populated from CAB definition / CAB meeting as well and in that case may be your script not work. So please check all the scenarios.
	*************************************************************************************************************
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 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]
****************************************************************************************************************
