Question On Termination Form

Priyadarshini M
Tera Contributor

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

 

6 REPLIES 6

Peter Bodelier
Giga Sage

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.

Anand Kumar P
Giga Patron
Giga Patron

Hi @Priyadarshini M ,

You can create a script include

AnandKumarP_0-1700125302405.png

 

AnandKumarP_1-1700125342368.png

 

AnandKumarP_2-1700125356550.png

 

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

Hi @Priyadarshini M ,

Mark it as solution proposed if it serves your purpose.

Thanks,

Anand

Dr Atul G- LNG
Tera Patron
Tera Patron

@Priyadarshini M 

 

  1. var nd = new GlideDateTime(gs.nowDateTime());
  2. gs.print('current date is :'+nd);
  3. var fd = new GlideDateTime(nd);
  4. fd.addDays(30);
  5. 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]

****************************************************************************************************************