Total duration on Change Request

User382122
Tera Contributor

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! 

2 ACCEPTED SOLUTIONS

Anand Kumar P
Giga Patron
Giga Patron

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

 

 

View solution in original post

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

View solution in original post

5 REPLIES 5

Anand Kumar P
Giga Patron
Giga Patron

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

 

 

Hi Anand! 

 

Thanks for your response would this be an  on before or after business rule? 

 

Respectly, 

 

Alicia 

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

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?