- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 01:44 AM - edited 11-13-2023 01:46 AM
Hi All,
I am developing a catalog form where user selects the start data as today, then end date field should automcatlly popuate after 30 days.
We have to write client script when on change. anyone script. Please suggest .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 02:05 AM
Hi @Jyo090
You can try following onChange script on start_date variable.
function onChange(control, oldValue, new value, isLoading){
if(isLoading || newValue === ''){
}
var start_date_number = getDateFromFormat(g_form.getValue('start_date'), g_user_date_format);
var start_date = new Date(start_date_number);
var end_date = new Date();
end_date.setDate(start_date.getDate() + 30);
var end_date_str = formatDate(end_date, g_user_date_format);
var date_arr = end_date_str.split(' ');
g_form.setValue('end_date', date_arr[0]);
}
Please mark my answer helpful and accept as solution if it helped 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 01:49 AM
Hi @Jyo090
There are 2 ways, as I think:
Try to use property. ( check the knowledge base property , which add 365 days in review date)
or
via script. I am not a coder but this link will help you:
https://www.servicenow.com/community/developer-forum/add-30-days-to-expected-date/m-p/1476187
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 02:02 AM - edited 11-13-2023 02:24 AM
Hi @Jyo090 ,
Can u try below code :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var endDate = new Date(g_form.getValue(start_date));
endDate.setDate(endDate.getDate() + 30); // Format the end date and set it in the end date field
g_form.setValue(end_date,endDate);
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 02:05 AM
Hi @Jyo090
You can try following onChange script on start_date variable.
function onChange(control, oldValue, new value, isLoading){
if(isLoading || newValue === ''){
}
var start_date_number = getDateFromFormat(g_form.getValue('start_date'), g_user_date_format);
var start_date = new Date(start_date_number);
var end_date = new Date();
end_date.setDate(start_date.getDate() + 30);
var end_date_str = formatDate(end_date, g_user_date_format);
var date_arr = end_date_str.split(' ');
g_form.setValue('end_date', date_arr[0]);
}
Please mark my answer helpful and accept as solution if it helped 👍✅
Anvesh