- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 09:22 AM
Hello all,
I want to see about creating a field called "Total CR Duration". With code that looks a little something like this:
var srt = g_form.getValue(current.start_date);
var end= g_form.getValue(current.end_date);
if (start != "") & (end != ""){
// calulated the duration start + end to give the total total and have it calulate in the "Total CR Duration" field.
}
New to developing. Please help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 09:48 AM - edited 09-26-2023 09:50 AM
Hi @User382122 ,
var start = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
if (start && end) {
var startDate = new GlideDate(start);
var endDate = new GlideDate(end);
var duration = new GlideDuration(startDate, endDate);
var durationDays = duration.getDisplayValue();
g_form.setValue('total_cr_duration', durationDays);
]
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 10:21 AM
Hi @User382122 ,
The script i have provide at client side if you want script in business rule use below script according to your requirement you can use before br.
var start = current.getValue('start_date');
var end = current.getValue('end_date');
if (start && end) {
var startDate = new GlideDate(start);
var endDate = new GlideDate(end);
var duration = new GlideDuration(startDate, endDate);
var durationDays = duration.getDisplayValue();
current.setValue('total_cr_duration', durationDays);
}
Kindly mark it as 'Helpful' and consider marking it as the proposed solution if it meets your requirements.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 05:19 AM
Hi @User382122 ,
Try this below script i have tested in background script its working mark helpful and solution proposed if its works for you.
var start = '2023-09-01';/replace with current.start date variable
var end = '2023-09-15';/replace with current.end variable
if (start && end) {
var startDate = new GlideDateTime(start);/
var endDate = new GlideDateTime(end);
var durationMs = endDate.getNumericValue() - startDate.getNumericValue();
var durationDays = durationMs / (1000 * 60 * 60 * 24);
gs.print(durationDays);
}
Thanks,
Anand