How to calculate / set a date/time field (Planned end date) based on another date/time AND duration type field?

jas101
Tera Expert

Hi all, Re our CHG form I'm looking for assistance on how I can set/calculate the 'Planned end date' (type: date/time) field from the values entered on a 'Planned start date' (type: date/time) field and a new/custom 'Duration' (type: duration) field. I.e. user enters the Planned start date, enters how long the change is to take and then the Planned end date is automatically calculated / set.

While I have been able to successfully set the 'Duration' value based off on 'Planned start date' and 'Planned end date' values using the 'Calculated Value' attribute on the 'Duration' field, I have not been able to set 'Planned end date' based on 'Planned start date' and 'Duration'.

Many thanks in advance!

7 REPLIES 7

Harish Ragz
Kilo Guru

Up to my understanding, You are going to calculate  'Planned end date' (type: date/time) field based on  'Planned start date' (type: date/time) field and a new/custom 'Duration' (type: duration) field. If it is correct Once check the below link. It may help you.

BR to Set Duration (IDEA.Opened to DEMAND.Closed

Please Hit Correct(If it is a correct solution) or Hit Helpful(If it is useful).

Hi, thanks for the reply but from what I can tell the linked post is using a business rule to set a 'Duration' type value. I actually want to set/calculate a date/time value (for CHG field 'Planned end date') using the values from:

Planned start date (a date/time type field)
+
Duration (a duration type field)
=
Planned end date (a date/time type field)

Ideally this will be client based so it updates on change of either first two fields as opposed to after a form save.
Thanks for any further help in advance.

 

Once try with below script. It may help you.

var gr= new GlideRecord('Required_table_Name');

var dur = new DurationCalculator();

dur =gr.Planned_start_date.dateNumericValue() + gr.duration.dateNumericValue();

gr.Planned_end_date.setDateNumericValue(dur);

Once check the below link.

Set a duration field value

Thanks Harish, although I'm not having much like with this script I'm afraid. Can you elaborate on whether this was for a business rule or a client script?