Computation of Weeks in 2 different Date and Display it to Duration Date Field.

Jeck Manalo
Tera Guru

 

Hi,

 

How can I display the weeks on "Duration Date" (u_duration_date)

JeckManalo_0-1704932242781.png

 
Created it using BR when to run before insert/update
 
var start = new GlideDateTime(u_start_date);
var end = new GlideDateTime(u_end_date);
var dur = new GlideDuration();

dur = GlideDateTime.subtract(start, end);

gs.print(dur.getDisplayValue());
gs.print(dur.getDayPart());

var days = dur.getDayPart();
var weeks = parseInt(days/7);

g_form.setValue(u_duration_date, gs.print(weeks));
1 ACCEPTED SOLUTION

ahefaz1
Mega Sage

 

var start = new GlideDateTime(current.getValue('u_start_date'));
var end = new GlideDateTime(current.getValue('u_end_date'));
var dur = new GlideDuration();

dur = GlideDateTime.subtract(start, end);
var days = dur.getDayPart();
var weeks = parseInt(days/7);

current.setValue('u_duration_date' , weeks);

@Jeck Manalo ,

 

You cannot use g_form in a business rule.

I think you need to add this to your BR

 

 

current.setValue("u_duration_date" , weeks);

 

 

 

Thanks,

View solution in original post

7 REPLIES 7

@Jeck Manalo ,

 

I just tested it in my PDI and works fine.

What is the type for the duration, start date and the end date fields?

 

Thanks,

 

I found out that the issue is the type. I set duration into integer.

 

Thank you for your help its big help for me.

JeckManalo_0-1704936668475.png

 

@Jeck Manalo ,

Glad it helped. Thank you for reaching out.