- 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-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:03 AM
Hi Anand!
Thanks for your response would this be an on before or after business rule?
Respectly,
Alicia
- 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 04:59 AM
Hi Anand,
I just realized that I may need more to this script. the above script isnt working. I think that we need to somehow add the total number of days from the date plus the total number of time and then have that displayed? Please let me know if you can still help with this?