Question On Termination Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 12:20 AM
Hi There,
I Have Termination cat item, and in that I have two date Type variables,
1) Start date, 2) End Date
In this case I want to achieve is, when Start date is selected as 01/Jan/2024, then End Date field should auto populate as 01/Feb/2024, (End date should be grater than 30 days of Start Date).
Can somebody please help me on this, how can i achieve this.
Thanks,
Priya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 01:02 AM
Hi @Priyadarshini M,
You could use below onChange client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var startDate = getDateFromFormat(g_form.getValue('start_date'), g_user_date_format);
if (!startDate) {
return;
}
var endDate = new Date(startDate);
endDate.setDate(endDate.getDate() + 30);
g_form.setValue('end_date', endDate.toISOString());
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 01:03 AM
Hi @Priyadarshini M ,
You can create a script include
Client script-----
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert(newValue);
var ga = new GlideAjax('getvalues');
ga.addParam('sysparm_name','mydatefunction');
ga.addParam('sysparm_date',newValue);
ga.getXML(cb);
function cb(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('end_date',answer);
}
}
Script include---
var getvalues = Class.create();
getvalues.prototype = Object.extendsObject(AbstractAjaxProcessor, {
mydatefunction:function()
{
var dt=this.getParameter('sysparm_date');
var dtob=new GlideDateTime(dt);
dtob.addDaysUTC(30);
return dtob.getDate();
},
type: 'getvalues'
});
Please mark it as solution proposed and helpful if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 12:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 02:33 AM
- var nd = new GlideDateTime(gs.nowDateTime());
- gs.print('current date is :'+nd);
- var fd = new GlideDateTime(nd);
- fd.addDays(30);
- gs.print('future date will be:'+fd);
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]
****************************************************************************************************************