- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 02:59 PM
Hello - I've planned start date and planned end date in change module. We want to calculate the duration between the two dates in a seperate field. Thoughts on BR script? I tried below with condition that date fields aren't blank but it doesn't seem to work.
calculateDiff();
function calculateDiff(){
var outage_start = g_form.getValue('start_date');
var outage_end = g_form.getValue('end_date');
var ajax = new GlideAjax('AjaxDurCalc');
ajax.addParam('sysparm_name','durCalc');
ajax.addParam('sysparm_strt',start_date);
ajax.addParam('sysparm_end',end_date);
ajax.getXMLWait();
var answer = ajax.getAnswer();
g_form.setValue('u_estimated_task_duration', answer);
}
Solved! Go to Solution.
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 03:04 PM
You can use below code to calcuate duration betweeen two dates.
- getTimeDiff();
- function getTimeDiff(){
- var startDate = current.u_start_date.getGlideObject();
- var endDate = current.u_end_date.getGlideObject();
- current.u_duration = gs.dateDiff(startDate.getDisplayValueInternal(),endDate.getDisplayValueInternal(),false);
- }
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 03:04 PM
You can use below code to calcuate duration betweeen two dates.
- getTimeDiff();
- function getTimeDiff(){
- var startDate = current.u_start_date.getGlideObject();
- var endDate = current.u_end_date.getGlideObject();
- current.u_duration = gs.dateDiff(startDate.getDisplayValueInternal(),endDate.getDisplayValueInternal(),false);
- }
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2017 11:31 AM
Works perfectly with duration field type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2017 04:33 AM
Hi sachin, sachin.namjoshi
I am new to service now !
I have two fieldsstart date and end date. if the end date is greater than 30 days it should give an alert.
i have written a client script which is working in maintain items Try it but it is not working in service portal.
how can i display an alert box if end date is more than 30 days of start date using glide ajax.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018 01:19 AM
Hi sachin.namjoshi,
How to put the source code on the client script or where?
Thank you