How to calculate / set a date/time field (Planned end date) based on another date/time AND duration type field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2018 09:27 AM
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!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2018 10:10 AM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2018 02:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2018 08:15 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2018 09:24 AM
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?