How can we set end date as one month from today's date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 02:37 AM
How can we set end date as one month from today's date?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 03:29 AM
Hi Burra,
You can either write onLoad or onChange Client script and set the date after one month from the below code:
or you can also write this in Before BR:
- var gdt = current.u_last_test_date.getGlideObject();
- if(current.business_criticality=='1 - Critical'){
- current.u_next_test_date=gdt.addDays(182); //adding 182 days to last tested date
- }
Also see this link:
Client Script Date/Time Functions
Regards,
Shamma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2017 02:50 AM
Hi Shamma,
We can not use "Current" object in Client scripts.
Thanks,
Buura
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2017 03:32 AM
Hi Burra,
The example I have given that is for On Before Business Rule not Client Script.
You cannot do this directly in Client script you need to write the Script Inlcude and then use Glideajax in your Client script:
See below:
Client Script:
- var cdt = g_form.getValue('due_date'); //Choose the field to add time from
- var addtime = 3; //The amount of time to add
- var addtype = 'day'; //The time type. Can be second, minute, hour, day, week, month, year.
- var ajax = new GlideAjax('ClientDateTimeUtils');
- ajax.addParam('sysparm_name', 'addDateTimeAmount');
- ajax.addParam('sysparm_fdt', cdt);
- ajax.addParam('sysparm_addtime', addtime);
- ajax.addParam('sysparm_addtype', addtype);
- ajax.getXML(doSomething);
- function doSomething(response){
- var answer = response.responseXML.documentElement.getAttribute("answer");
- //You could then take the new Date/Time answer and set the value of another field.
- g_form.setValue('expected_start', answer);
- alert(answer);
- }
Script Include:
- addDateTimeAmount: function(){
- var firstDT = this.getParameter('sysparm_fdt'); //First Date-Time Field
- var addTYPE = this.getParameter('sysparm_addtype'); //What to add - second (addSeconds()), minute (need to add conversion), hour (need to add conversion), day (addDays()), week (addWeeks()), month (addMonths()), year (addYears())
- var addTIME = this.getParameter('sysparm_addtime'); //How much time to add
- var day = GlideDateTime(firstDT);
- if(addTYPE == 'second'){day.addSeconds(addTIME);}
- else if (addTYPE == 'minute'){day.addSeconds(addTIME*60);}
- else if (addTYPE == 'hour'){day.addSeconds(addTIME*(60*60));}
- else if (addTYPE == 'day'){day.addDays(addTIME);}
- else if (addTYPE == 'week'){day.addWeeks(addTIME);}
- else if (addTYPE == 'month'){day.addMonths(addTIME);}
- else if (addTYPE == 'year'){day.addYears(addTIME);}
- else {day.addDays(addTIME);}
- //return "First Date: " + firstDT + " -Time to Add: " + addTIME + " -Add Type: " + addTYPE + " -Added Time: " + day;
- return day;
- }
This would work.
Regards,
Shamma