Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

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,

not working

@Jeck Manalo ,

 

just updated it again. Please try.

 

Thanks,

same result 😞