Normal Change lead time
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 06:22 AM
Hello to everyone,
I have write the on change client script for normal change planned start date lead time 24 hours but it takes the 30 hours time The script follws below:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var startDate = g_form.getValue("start_date");
var endDate = g_form.getValue("end_date");
var date_in_5 = new Date();
date_in_5.setDate(date_in_5.getDate()+1);
var format = g_user_date_time_format;
// get date strings into a number of milliseconds since 1970-01-01
var startDateMs = getDateFromFormat(startDate, format);
var endDateMs = getDateFromFormat(endDate, format);
var dd = date_in_5.getDate();
var mm = date_in_5.getMonth()+1; //January is 0!
var hh = date_in_5.getHours();
var min = date_in_5.getMinutes();
var ss = date_in_5.getSeconds();
if(dd<10) {
dd='0'+dd;
}
if(mm<10) {
mm='0'+mm;
}
if(hh<10) {
hh='0'+hh;
}
if(min<10) {
min='0'+min;
}
if(ss<10) {
ss='0'+ss;
}
date_in_5 = dd + "/" + mm + "/" + date_in_5.getFullYear() + " " + hh + ":" + min + ":" + ss;
var date_in_5MS = getDateFromFormat(date_in_5, format);
if (startDateMs > endDateMs && endDate != ''){
g_form.setValue('start_date', '');
g_form.showErrorBox('start_date','Start date has to be before end date');
}
if(g_form.getValue('type') == 'normal'){
if(startDateMs < date_in_5MS){
g_form.setValue('start_date', '');
g_form.showErrorBox('start_date','Normal change lead time is 24 Hours');
}
}
}
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 06:29 AM
Hi,
Why not use No Code ui policy conditions like this and have a much simpler implementation. In the script part you can throw the error.
-Anurag
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 07:13 AM
Hi @siva44
@Anurag Tripathi suggested correctly. Use UI policy and no need to build code or use can create property and use that property to validate.
*************************************************************************************************************
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]
****************************************************************************************************************